Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.

Bash: If statement with dash o

  • 23-04-2019 11:57AM
    #1
    Registered Users, Registered Users 2 Posts: 5,751 ✭✭✭


    Hi, can anyone deduce what the if statement means below, specifically the "ash o" parts. That argument doesnt exist in the man page for "test" or "if".
    check_params()
    {
    if [ ! "${PATH}" -o ! "${ACTION_TYPE}" -o ! "${LU_PATH}" ]; then
        usage_msg
        exit 1
    fi
    }
    


Comments

  • Registered Users, Registered Users 2 Posts: 7,544 ✭✭✭BrokenArrows


    its an argument to whatever executable is being executed.
    The ! takes the last argument from the console history and puts it in there.

    So what it does really depends on what is being executed in the history.


  • Registered Users, Registered Users 2 Posts: 1,110 ✭✭✭Skrynesaver


    $ if [ 1 -eq 1 -o 2 -gt 3 ] ; then echo OK;fi
    OK
    
    $ if [ 1 -eq 0 -o 2 -gt 3 ] ; then echo OK;fi
    
    $ if [ 1 -eq 0 -o 2 -gt 1 ] ; then echo OK;fi
    OK
    

    It's the equivalent of an OR


  • Registered Users, Registered Users 2 Posts: 2,415 ✭✭✭Singer


    $ if [ 1 -eq 1 -o 2 -gt 3 ] ; then echo OK;fi
    OK
    
    $ if [ 1 -eq 0 -o 2 -gt 3 ] ; then echo OK;fi
    
    $ if [ 1 -eq 0 -o 2 -gt 1 ] ; then echo OK;fi
    OK
    

    It's the equivalent of an OR

    Yep. The Advanced Bash Scripting Guide has been my go-to guide for this stuff for... too many years:

    http://tldp.org/LDP/abs/html/comparison-ops.html


  • Registered Users, Registered Users 2 Posts: 5,751 ✭✭✭veryangryman


    Thanks guys. Very helpful


Advertisement