Reputation: 16503
i=0
if [$i -eq 0]
then
echo "i is equal to 0"
else
echo "NOT EQUAL <><><><><><><><><><><><><><><><><><><>"
fi
it is part of a bash script and it always takes the else branch. I'm completely new to bash so its probably something silly
Upvotes: 3
Views: 74
Reputation: 69198
You need spaces after '[' and before ']'. '[' is a command.
Upvotes: 1
Reputation: 31182
you need [ $i
instead of [$i
.
This is because the [
is a builtin command and $i
should be it's first parameter. If you miss the space between command and parameter, then the shell will look for [$i
command and after evaluation will tell you that there is no [0
command to be executed.
Upvotes: 5