Terms of Service Privacy Policy Contact Us

leistware.com

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

    00-2A-95

    UPDATED 2017-09-05 01:29:02.0

    Syntax


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

    Standard syntax of the if statement:




    CREATED 2017-09-05 01:32:11.0

    00-2A-96

    UPDATED 2017-09-05 01:32:16.0

    Shorthand


    $ [ 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

    00-2A-97

    UPDATED 2017-09-05 01:32:41.0

    Knowledge

    Page Server: Ithica

    DBID: db.wam

    ©2012 Leistware Data Systems

        Hello anonymous