Bash- if clause doesn't work correctly -
this question has answer here:
i want make shutdown script , doesn't work intended. wrote.
echo "wanna shutdown (y/n)?" read answer if [ $answer=="y" ] sudo shutdown -p else printf "something...." whatever press shuts down. why?
you need put spaces around == operator. otherwise test expression single word, , non-empty words test successfully.
in addition, if wish portable, should use = instead of ==. , wise double quote variable expansions because [ won't you.
if [ "$answer" = y ]; on other hand, if using bash (or ksh or zsh) use more forgiving [[ conditional expression:
if [[ $answer = y ]];
Comments
Post a Comment