Pages

Saturday, January 11, 2014

OR & AND conditions in shell scripts

OR Statement in shell scripts

|| is known as OR statement in shell script.

Eg:


# id user1 || useradd user1

In the above example if the user1 exist in the system the second command will not be executed. If the user1 does not exist second command will be executed.

If first command returns true second will not exist run. if the command is false second will be executed.

AND Statement in shell scripts


 Eg:

&& is known as AND in shell script


#  [ -d /tmp/test ] && rm -rf /tmp/test

 If the first command is true the second command will be executed. If the first
false second command second will not executed.


No comments:

Post a Comment