Two conditions in a bash if statement
bash, conditional-statements, if-statement
Solution
You are checking for the wrong condition.
if [ "$choice" != 'y' ] && [ "$choice1" != 'y' ];
The above statement is true when `choice!='y'` and `choice1!='y'`, and so the program correctly prints "Test Done!".
The corrected script is
echo "- Do You want to make a choice ?"
read choice
echo "- Do You want to make a choice1 ?"
read choice1
if [ "$choice" == 'y' ] && [ "$choice1" == 'y' ]; then
echo "Test Done !"
else
echo "Test Failed !"
fi
Problem
I'm trying to write a script which will read two choices, and if both of them are "y" I want it to say "Test Done!" and if one or both of them isn't "y" I want it to say "Test Failed!" Here's what I came up with: ``` echo "- Do You want to make a choice?" read choice echo "- Do You want to make a choice1?" read choice1 if [ "$choice" != 'y' ] && [ "$choice1" != 'y' ]; then echo "Test Done!" else echo "Test Failed!" fi ``` But when I answer both questions with "y" it's saying "Test Failed!" instead of "Test Done!". And when I answer both questions with "n" it's saying "Test Done!" What have I done wrong?