0

I am messing with shell scripting and stuck in some comparison in while loop

while [$size -le $MAX] 
do
------
done

The above loop is not working. What am I doing wrong ?

2 Answers 2

4

You don't have spaces around [ and ].

Say:

while [ $size -le $MAX ] 

[ is a command, also known as test. When you say [$size, the shell interprets it as a string and not as a command.

Sign up to request clarification or add additional context in comments.

1 Comment

Thaank u devnull and @dogbane for replying . That solved my headache. That little space raged me a bit.
0

You need spaces around the brackets, like this: while [ $size -le $MAX ].

However, it's more readable if you use bash's arithmetic expression instead:

while (( size <= MAX )) 
do

done

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.