1

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
1
  • 1
    For a start, most of your script is inside a string. Once you've taken care of that, use shellcheck.net Commented Sep 19, 2016 at 15:59

1 Answer 1

2

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 ]
                         #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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.