Bash: Two conditions in if -


i'm trying write script read 2 choices, , if both of them "y" want "test done!" , if 1 or both of them won't "y" want "test failed!" here's came with:

echo "- want make choice ?" read choice echo "- want make choice1 ?" read choice1 if [ "$choice" != 'y' ] && [ "$choice1" != 'y' ]; echo "test done !" else echo "test failed !" fi 

but when answer both questions "y" it's saying "test failed!" instead of "test done!". , when answer both questions "n" it's saying "test done!" i've done wrong ?

you checking wrong condition.

if [ "$choice" != 'y' ] && [ "$choice1" != 'y' ]; 

the above statement true when choice!='y' , choice1!='y', , program correctly prints "test done!".

the corrected script is

echo "- want make choice ?" read choice echo "- want make choice1 ?" read choice1 if [ "$choice" == 'y' ] && [ "$choice1" == 'y' ]; echo "test done !" else echo "test failed !" fi 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -