Answer the question
In order to leave comments, you need to log in
How do logical operators work in BASH?
Imagine a simple sequence of commands
cd ~/dir1 && cd ~/dir2 && echo "Success" || echo "Failed"
1 && 1 && echo "Success"
Answer the question
In order to leave comments, you need to log in
As always, the title is "How do logical operators work?", but in fact the question is "why is error code 0 interpreted as true". "Where is the logic, where is the reason?" :)
While the voiced question is actually interesting.
This is how logical operators work, not only in bash. In PHP, you can write exactly the same
true /*false*/ and print "Success" or print "Failed";
and get the same result. Since the successful execution of the command returns 0. Which is completely contrary to the algebra of logic.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question