Advertisement
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.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Bash: If statement with dash o

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


    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,546 ✭✭✭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,762 ✭✭✭veryangryman


    Thanks guys. Very helpful


Advertisement