shell script to print '*' triangle


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script to print '*' triangle
# 1  
Old 01-09-2008
Question shell script to print '*' triangle

plz tell me how to print * triangle

like this

*
**
***
****
*****
# 2  
Old 01-09-2008
Can you dictate coding you have done on it. so that I can better help you out?

Regards,
Raj Kumar Arora
# 3  
Old 01-09-2008
for i in 1 2 3 4 5
do
j=0;
while [ $j -lt i ]
do
echo "* \c"
j=$(( j + 1 ))
done
echo ""
done
# 4  
Old 01-09-2008
Code:
#!/bin/ksh

str="*"

for i in 1 2 3 4 5
do
   echo "$str"
   str="$str *"
done

# 5  
Old 01-09-2008
thanks fpmurphy its working buddySmilie
# 6  
Old 01-09-2008
A curious way:
Code:
>awk 'BEGIN{    while ( i < 5 )
               {
               i++
               $i=OFS="*"
               print
               $i=""
               }
}'
*
**
***
****
*****


Last edited by Klashxx; 01-09-2008 at 12:40 PM..
# 7  
Old 01-09-2008
Hi Klashxx,

What OFS in Print statement does?
I am new to AWK so i didnt have no idea what OFS means?

Thanks,
Raamc
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print statement in shell script

Hi All, when I executed the query in normal unix mode, the output is expected. if I executed the query using shell script, I am not getting the result. not sure whether I need to use dbms_output.put_line or echo. dbms_output.put_line("COUNTRY_CODE"||" "||"SUB_TYPE"||" ... (3 Replies)
Discussion started by: arun888
3 Replies

2. Shell Programming and Scripting

Print 1 to 10 with space in shell script

Hi, I want to print 1 to 10 or upto any number sequentially with space in a single line. Like, 1 2 3 4 5 6 7 ...... In shell script only.. Can anyone plz help me. Thanks: (14 Replies)
Discussion started by: arup1980
14 Replies

3. Fedora

Shell Script - awk, begin, for and print

pointsb=`awk -v a2="$a2" -v b2="$b2" -v c2="$c2" -v yb="$yb" -v yc="$yc" \ 'BEGIN { for (y=yc; y<=yb; y++) { x = a2*y*y+b2*y+c2; print x, y }; }'` I am learning shell script. I was reading a script and got confused in this line. I understood that awk is allowing to assign the variable. But... (10 Replies)
Discussion started by: agriz
10 Replies

4. Shell Programming and Scripting

Help me with shell script command to print

I have a file with similar line like below /u13/orabkup/u13/orabkup/abcd/arc82.123 Now I need to have only u13/orabkup/abcd/arc82.123 rather than /u13/orabkup/u13/orabkup/abcd/arc82.123 Kindly help me to print /u13/orabkup/ only once and the file name abcd/arc82.123.. Thanks & Regards... (1 Reply)
Discussion started by: anitha11889
1 Replies

5. Ubuntu

How to creat a half-triangle in bash(Ubuntu)?

how to create a half-triangle like this and that will accept an input from the user, Dimension of the triangle will be based on the users input. example: enter the dimension: 5 ***** -**** --*** ---** ----* thankyou (3 Replies)
Discussion started by: carljoses
3 Replies

6. Shell Programming and Scripting

How to print backslash in shell script using awk?

I found that echo "aaa" | awk '{print ",\\";}' works, and it will give "\". but ddd=`echo "aaa" | awk '{print ",\\";}'`; echo $ddd will not work. Could anyone tell me why? thank you. (8 Replies)
Discussion started by: wxuyec
8 Replies

7. Shell Programming and Scripting

need help in writing shell script to generate pascal's triangle

Hi :) I am learning shell scripting, I need help, I would like to have a script that produces pascal's triangle as shown in the picture http://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Pascal%27s_triangle_5.svg/250px-Pascal%27s_triangle_5.svg.png plz, help it's urgent thanks in... (1 Reply)
Discussion started by: angel1
1 Replies

8. Shell Programming and Scripting

shell script to print words having first and last character same.

Hi I want to write a shell script to print only those words from a file whose beginning and last character are same. Please help. Thanks, vini (5 Replies)
Discussion started by: vini kumar
5 Replies

9. UNIX for Dummies Questions & Answers

Linux Shell Question: how to print the shell script name ?

Suppose I have a script named "sc.sh" in the script how to print out its name "sc.sh"? (3 Replies)
Discussion started by: meili100
3 Replies
Login or Register to Ask a Question