Login Register






Star pattern in Shell filter_list
Author
Message
Star pattern in Shell #2
I'm learning Shell programming now, and got a homework that wants me to display this :
Quote:*
**
***
****
*****

Now, I tried it using the while loop, as I am still due to learn the for loop syntax in shell.

Here's my code:
PHP Code:
echo "enter size of star" read n i=1 j=1 while [ $i -le $n ] do while [ $j -le $i ] do echo "*" j=`expr $j + 1` done echo -n " " i=`expr $i + 1` done

The result is this:
Quote:*
*
*
*
*

What I have in mind: echo "*" prints * in a new line normally
and echo -n "*" prints * in the same line without going for a new line.
The new line thing is still not clear to me, so Correct me if i'm wrong.

In C or C++ "\n" did the trick for me.
[Image: MUJ8qSW.png]
-----------------------------------
Now learning:
Android Development, Java
Working on:
An FTP Client for Android
-----------------------------------






Messages In This Thread
Star pattern in Shell - by alok9shm - 09-08-2014, 09:20 AM
Star pattern in Shell - by alok9shm - 09-08-2014, 09:20 AM