0

I am trying to print the stars below on the screen using for or while loop. I don't know if I should treat as a string or what. If it is a string should I use foreach loop, just don't know where to start really.

******************
   ***********
     *******
       ***
        *

I am trying to get it to work even though I know it is wrong, but I am trying. Thanks for the advice.

#!/bin/bash

whilefunc() {
    echo "*************"
    echo"  ******  "
    echo"   ****   "
 }

i=2

while [ $i = 2 ]
do
    whilefunc
done

exit
6
  • Did you try anything so far, some code available? Commented Oct 6, 2011 at 15:36
  • 1
    Nobody will do your homework for you. People here can help but you have to try something. Commented Oct 6, 2011 at 15:39
  • @LucM The trouble is, they will... Commented Oct 6, 2011 at 15:45
  • If this is homework, please add a "homework" tag. Commented Oct 6, 2011 at 18:13
  • Keith thanks this is not a homework at all. I'm doing this on my own, just don't know which loop to use sine * is not a number and I don't know if I have to treat it as a string Commented Oct 6, 2011 at 20:21

1 Answer 1

1

Any loop will do, and just escape the * with backslash i.e.

while [[ : ]]; do
  echo -e \*****
  echo -e  \***
  echo -e   \*
  # do whatever else you need to do
done
Sign up to request clarification or add additional context in comments.

1 Comment

thanks my friend the only thing I guess it will run for ever I just wanted to run once

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.