My code:
#!/bin/sh
#filename:choose.sh
read choose
[ "$choose" == "y" -o "$choose" == "Y" ] && echo "Yes" && exit 0
[ "$choose" == "n" -o "$choose" == "N" ] && echo "No" && exit 0
echo "Wrong Input" && exit 0
But when I execute
sh ./choose.sh
terminal prompt me that
[: 4: n: :Unexpected operator
[: 5: n: :Unexpected operator
Is there any mistake in my bash script? Thanks!
shtobash. Some distributions don't offer a trueshanymore. Although some will argue (and I tend to agree) that if you're writing a script to be portable, write it inshinstead ofbash.source foobar.shnot./foobar.sh${choose}BLAHapproach -- it's much better to just quote, with"$choose"; constant prefixes/suffixes haven't been needed since the 1970s (as long as features marked obsolescent in the current POSIXteststandard, like-aor-o, are avoided).