Terms of Service Privacy Policy Contact Us


Boolean Logic

The if statement otherwise known as boolean logic is used for branch execution. This is a pretty common construct in most all languages. Bash is no different however boolean logic can get sticky for those not quite used to the shell.

CREATED 2017-09-05 01:29:02.0


UPDATED 2017-09-05 01:29:02.0


if [ -e $someFile ] then    // some processing fi

Standard syntax of the if statement:

CREATED 2017-09-05 01:32:11.0


UPDATED 2017-09-05 01:32:16.0


$ [ expression ] && <action if true> ¦¦ <action if false> $ [ expression ] && <action 1 if true>;<action 2 if true>; ¦¦ <action if false>

There is a shorthand version of the if statement (boolean logic) in bash but it can make your code a little hairy. Especially for those not familiar with your writing style.

For simple true or false; one action each; statement...

If there is more than one action on either side terminate each action with a semi-colon (;):

CREATED 2017-09-05 01:32:29.0


UPDATED 2017-09-05 01:32:41.0


Page Server: Ruger

DBID: db.wam

©2012 Leistware Data Systems

      Hello anonymous