Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Test if parameter is set



Thorsten Kampe wrote:
> how can I test if a parameter is set?
>
> Like in...
>
> if $VAR_IS_SET; then
>     print Variable is set
> else
>     print Variable is not set
> fi

In zsh:

if (( ${+parameters[foo]} )); then
   : set
else
   : unset
fi


In POSIX shells:

if [ x${foo+set} = xset ]; then
   : set
else
   : unset
fi

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925



Messages sorted by: Reverse Date, Date, Thread, Author