Unix Shell Script: While loop Unix Shell Script: While loop unix unix

Unix Shell Script: While loop


As you simply append the latest count to the line output, simply do so as text.

#!/bin/basha=0out=''while [ $a -lt 10 ]do    out=$out$a    echo $out    a=`expr $a + 1`done

Also, le is less or equal, so you end up with 10. Use lt 10 or le 9.


If you use bashshell, you can take advantage of sequence expressions of the form {x..y} and use the special parameter $_ which usually expands to the last argument to the previous command.

#/bin/bashi=for i in {0..9}do     echo "$_$i"done


a=0                                                                           b=1                                                                                             while [ $a -lt 10 ]                                                                         do                                                                                                                                                                   a=0                                                                                                                                                          while [ $a -lt $b ]                                                                                                                                          do                                                                                                                                                           echo -n $a                                                                                                                                                   a=`expr $a + 1 `                                                                                                                                         done                                                                                                                                                     echo                                                                                                                                                             b=`expr $b + 1`                                                                                                                                                  done