How-to: Perform Conditional Execution

An AND list has the form 
 command1 && command2
command2 is executed if, and only if, command1 succeeds
An OR list has the form 
 command1 || command2
command2 is executed if, and only if, command1 fails 

A list is a sequence of one or more pipelines separated by one of the operators ';', '&', '&&', or '||', and optionally terminated by one of ';', '&', or a newline.

Of these list operators, '&&' and '||' have equal precedence, followed by ';' and '&', which have equal precedence.

If a command is terminated by the control operator '&', the shell executes the command asynchronously in a subshell. This is known as executing the command in the background. The shell does not wait for the command to finish, and the return status is 0 (true).

Related macOS commands

macOS How To

(追記) (追記ここまで)
Copyright © 1999-2026 SS64.com
Some rights reserved

AltStyle によって変換されたページ (->オリジナル) /