Otorrinolaringologista -man Otorrinolaringologista -man - 2 months ago 7
Bash Question

How to use user input into a while loop

Well, Im trying to practice a bit of shell script but Im stuck at this while loop excercise. I simply want to use whatever number the use inputs as the loop`s condition.

#!/bin/bash

a=0
input=""
echo "Type any number"

read $input

while [$a -lt $input]
do
echo $a
a=`expr $a + 1`
done

Answer

You might wonder to have such script:

#!/bin/bash

a=0
input=""
echo "Type any number" #here you forgot to close string with "

read input  #here you don't need $


while [ $a -lt $input ]  #note extra spaces after [ and before ]
do
   echo $a
   a=`expr $a + 1`

done