I tried it on my system, and it seems to work fine.
It could be because Bash 4.x is fussy about syntax (I'm on Bash 3.2), or it could be that you aren't specifying Bash when you run it:
$ sh test.sh
On many systems, this would run something like the Bourne shell. (On mine, it runs Bash in POSIX mode, so it still works). The ==
is not a valid test in Bourne shell (although it works in Bash and Kornshells). Using a single equals (=
) instead of a double equals will solve this issue.
You can also try using the standard line breaks instead of the modern way lines are broken in if
statements. Try this:
#!/bin/bash
echo "ca va (y/n)?"
read answer
if [ "$answer" = "y" ]
then
echo "yes"
else
echo "no"
fi