Reputation: 203
If there some difference between the bash of Mac OS and other linuxs'? I wrote a simple bash script named "test.sh" like this:
#!/bin/bash
MYVAR=abc
if [ $MYVAR = abc ]; then
echo "ok"
fi
When I run it in terminal, some error occurs:
./test.sh: line 3: syntax error near unexpected token `then'
./test.sh: line 3: `if[ $MYVAR = abc ]; then'
then I delete the character ";" before "then" and run the script again, some infos occurs:
./test.sh: line 3: if[ abc = abc ]: command not found
ok
./test.sh: line 5: syntax error near unexpected token `fi'
./test.sh: line 5: `fi'
Could someone tell me what's wrong with my script?
Upvotes: 2
Views: 6199
Reputation: 241768
[
is a command (same as test
). It must be separated by spaces on both sides.
Upvotes: 2
Reputation: 143051
Consider putting spaces into your file the way you put it in your example (if [
).
Upvotes: 4