Shell 如何在while循环中使用用户输入

Shell 如何在while循环中使用用户输入,shell,while-loop,sh,do-while,Shell,While Loop,Sh,Do While,嗯,我试着练习一点shell脚本,但我一直在做这个while循环练习。我只想使用使用输入的任何数字作为循环的条件 #!/bin/bash a=0 input="" echo "Type any number" read $input while [$a -lt $input] do echo $a a=`expr $a + 1` done 您可能想知道有这样的脚本: #!/bin/bash a=0 input="" echo "Type any number" #here

嗯,我试着练习一点shell脚本,但我一直在做这个while循环练习。我只想使用使用输入的任何数字作为循环的条件

#!/bin/bash

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

read $input

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

您可能想知道有这样的脚本:

#!/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 ]
                         #tricky part here is that '[' is a program 
                         #and '$a -lt $input ]' are just its params
                         #this is why you need add extra spaces     
do
   echo $a
   a=`expr $a + 1`

done

首先,大部分脚本都在字符串中。一旦你处理好了,使用