4

Now before you flag this as a duplicate please understand i did search for this problem and i already tried all of the solutions to no effect.

My script:

#!/bin/bash

echo "Enter the number 3"
read t1
if [$t1 -eq 3]; then
    echo "it is 3"
elif [$t1 > 3]; then
    echo "it is greater than 3"
fi

exit 0

The error i get is:

./g.sh: line 5: [3: command not found
./g.sh: line 7: [3: command not found
9

spaces needed if [ $t1 -eq 3 ]

  • you gotta be kidding me... Bash is one picky SOB. – Skilo Skilo Jan 18 '14 at 3:11
  • 4
    @SkiloSkilo it's not bash - [ is its own executable. It lives in /bin on my Mac, may be elsewhere in Linux. Program names always need spaces around them. – MattDMo Jan 18 '14 at 4:08
  • In this case [ is fine, however if your variable isn't in quotes or you want pattern matching, then use [[ ibm.com/developerworks/opensource/library/l-bash-test/… – spuder Jan 18 '14 at 5:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.