-->

How is conditional execution used in UNIX?

Conditional execution can be accomplished in UNIX with the use of control operators “and” and “or”. The and operator is represented as && and the syntax of their usage is :





This implies that the command 2 will only be executed if the command 1 returns an exit status 0.

The or operator is represented by ||. The syntax of using the or operator is:


This implies that command2 is executed if the command 1 returns a non-zero exit value.

Both the operators can be used together.

For ex.




This implies that command 2 will be executed if and only if command 1 executes or else command 3 will be executed.