LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Shell Script (https://www.linuxquestions.org/questions/programming-9/shell-script-259430/)

wcfour 11-26-2004 03:07 AM

Shell Script
 
Hi I am new to this forum, any help would be appreciated.

I am trying to figure out how to write a script to display the numbers 1 - 9 in a row (one at a time.) Using a while loop.
For example:
1
12
123
1234
etc...

thx

jlliagre 11-26-2004 03:22 AM

Looks like an assignement ...
Who ever want to do that in the real life ?

theYinYeti 11-26-2004 03:28 AM

Code:

line=
for number in 1 2 3 4 5 6 7 8 9; do
  line="${line}${number}"
  echo "$line"
done

or
Code:

line=
number=1
while [ $number -lt 10 ]; do
  line="${line}${number}"
  number=$(( $number + 1 ))
  echo "$line"
done


wcfour 11-26-2004 03:37 AM

script
 
theYinYeti

Thank you

jlliagre 11-26-2004 05:24 AM

That one is cooler :D
Code:

echo "1
12
123
1234
12345
123456
1234567
12345678
123456789" | while read s
do
echo $s
done


acid_kewpie 11-26-2004 05:31 AM

Can i Please remind LQ members that there is no benefit to another member's learning if you give them a straight solution to their course work. give hints, not soutions. thanks.

jlliagre 11-26-2004 06:05 AM

Quote:

Can i Please remind LQ members that there is no benefit to another member's learning if you give them a straight solution to their course work.
That was precisely my goal in my first reply, but theYinYeti missed it.
I provided a dumb answer later just for fun, I doubt wcfour will get an A+ with it ...

theYinYeti 11-26-2004 06:07 AM

Is that so? ... I was indeed surprised by the request... But then, I've done myself so strange things to achieve usefull results in shell scripting...


All times are GMT -5. The time now is 02:01 PM.