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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Bash: If statement with dash o

  • 23-04-2019 10:57am
    #1
    Registered Users, Registered Users 2 Posts: 5,660 ✭✭✭


    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,501 ✭✭✭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,660 ✭✭✭veryangryman


    Thanks guys. Very helpful


Advertisement