I want the command to be executed only if the previous command exit status was not 0.
i.e. Command 1 ^ Command 2 where command 2 is executed only if command 1 fails.
To do this, use the two-pipe ( || ) operator.
||
touch /asdf/fdasfds/fdasfdas || echo "Couldn't touch."
The second command is only executed when the first command returns a nonzero value, exactly as you specified.
I think it should be mentioned that OR does not have the same meaning as XOR ("exclusive" or "). See the truth table below.
"or" "xor" PQ (( $P || $Q )) (( ($P && ! $Q) || (! $P && $Q) )) 0 0 0 0 0 1 1 1 1 0 1 1 1 1 1 0
This should work:
command1 || command2
Source: https://habr.com/ru/post/1315135/More articles:How to achieve the ability to center tables without tables - htmlHow to work with multiple time zones in applications that store dates and times? - timezoneHow to implement historical version control? - c #Ada Guides: The Difference Between Annotated and Consolidated - adaASP.net MVC 2 Entity Framework Multi-Table Tutorial - repository-patternHow to make magento use a different category than the "Default Category" to generate the-nav header? - xmlHow to write a vim function to output the result of a system command? - vimWhat is the best way to support the many art sizes currently used by iOS? - iosNSTask and the NSPipe example for communicating with the objective-c command line - user-interfaceiPad Playing HTML5 Audio From A Dynamic Source (Servlet / jsp) - html5All Articles