2
#!/bin/bash

number=0
while [ $number -lt 10 ];do
echo "$number"
number='expr $number + 1'
done
echo 'script complete!'

=> this results in

0
./while.sh: line 4: [: too many arguments
script complete!

I've tried ...

while [ $number -lt 10 ]

to

while [ '$number' -lt 10 ]

and

while [[ $number -lt 10 ]]

which doesn't work at all..

1 Answer 1

2

You are using wrong quotes for expression evaluation; single quote(') instead of backquote(`). Try this..

number=`expr $number + 1`
Sign up to request clarification or add additional context in comments.

2 Comments

Two points about the original: in general you should use number=$(expr $number + 1) in place of backquotes, and you should use number=$(( number + 1)) in place of expr.
Or, even better, ((number++)). Option added to answer. :)

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.