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

Bourne Shell scripting help

  • 04-06-2009 2:52pm
    #1
    Closed Accounts Posts: 752 ✭✭✭


    Checking an enviroment variable is set

    What i can do simply in bash with
    if [ -z $ENV_VER ] ; then



    i have tied this on borne and cant get it to work wothout


    "sh: ENV_VER: Parameter not set."


    I have tried:(what i can remember trying)

    if [-n ${var:-x}]

    [ ! -z $var ] && echo "set" || echo "not"

    ${var:-'SomeDefault'}

    if [ "X${VAR}" != "X" ] ;then echo "hi" ;fi;


Comments

  • Registered Users, Registered Users 2 Posts: 39 Talon.ie




  • Registered Users, Registered Users 2 Posts: 4,240 ✭✭✭bullpost


    If you're still stuck I think you can use the test command to do this iirc.

    Look up the man page for test but it should be something like:

    if test $A then ......


  • Moderators, Technology & Internet Moderators Posts: 1,336 Mod ✭✭✭✭croo


    You sure
    if [ "X${VAR}" != "X" ] ;then echo "hi" ;fi;
    doesn't work?

    As is, it would only display "hi" when the VAR is set! Rather than when it is empty as you initially said. But I'm guessing that is a typo?
    if [ "X${VAR}" == "X" ] ;then echo "hi" ;fi;
    to say "hi" when VAR is not set

    A great way to test this things I find is to enabling debugging with set -x

    set -x
    if [ "X${VAR}" == "X" ] ;then echo "hi" ;fi;

    then at the prompt
    $ export VAR= (just to be sure!)
    $ ./script.sh
    ++ ''
    ++ echo hi
    hi

    $ export VAR=yes
    $ ./script.sh
    ++ ''


  • Closed Accounts Posts: 752 ✭✭✭JimmyCrackCorn!


    [ -z $A'' ]

    Works


Advertisement