Find the answer to your Linux question:
Results 1 to 2 of 2
Hello all, I am new to scripting and I am using C Shell Script. I can't find a way to check if an environment variable is defined/set already. I found ...
  1. #1
    Just Joined!
    Join Date
    Jun 2007
    Posts
    4

    Question:How to check if ENV_VAR is defined

    Hello all,

    I am new to scripting and I am using C Shell Script.

    I can't find a way to check if an environment variable is defined/set already.

    I found some test procedures like

    if ( -z somefile )
    # something to do here
    else
    # something to do here
    endif

    but all that i found check only file existence.

    Do you know any test procedure that i can put in an if statement to check whether an environment variable is defined.

    For example:

    if( -defined $MY_ENV_VAR )
    echo "env var defined"
    else
    echo "env var undefined"
    endif

    Thanks all.

  2. #2
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    Just check if the variable contains something/anything
    if [ $VAR ] ; then
    Can't tell an OS by it's GUI

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...