Friday, February 2, 2007

Check whether $ENV_VAR is set or not


If you want to see whether a particular env var is set or not set, write something like this in your script

$ if (set -u; : $HOME) 2> /dev/null
> then
> echo "HOME env is set"
> else
> echo "Not"
> fi

A simple alternative

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

No comments:

© Jadu Saikia www.UNIXCL.com