or operator not working
Can someone tell me why this doesn't work:
============================= PHASE="upgrade"; if [ "$PHASE" != "install" -o "$PHASE" != "upgrade" ] then echo "Nothing to be done here" else echo "Proceed with the next step" fi ============================= It always prints "Nothing to be done here" But if I remove the -o operator and the second condition, then it works. Some issue with -o operator i guess.. |
Dash? Bash? Ksh? Zsh?
Which one? |
Take a close look at the logic of that test. "If $PHASE is either unlike "install" or unlike "upgrade", then there's nothing to be done."
Under what circumstances will $PHASE not be unlike at least on of the two conditions? |
Shell is bash.
@Ser Olmy: If you take a closer look you can see that the variable PHASE is already set to "upgrade". So the if condition shouldn't match, but else condition should match. |
Actually, boolean logic for OR says that if the first test is true then the second never need be tested, hence, since PHASE is not equal to "install" is true the 'if' is executed and not the 'else'
|
If it is set to "upgrade" then it ALWAYS !="install" and correctly matches.
** grail types faster than I do... ** |
Thanks Grail.
I should have used AND operator and not OR operator :) |
Flawed logic. No matter what value PHASE has - 'install', 'upgrade' or any other 'rambo' value, it will always return TRUE.
Use instead Code:
if [[ "$PHASE" == "install" || "$PHASE" == "upgrade" ]] |
Sorry guys, that was such a silly mistake. Thanks all for your help.
|
Don't forget to mark as SOLVED once you have a solution.
|
All times are GMT -5. The time now is 02:04 PM. |