How to check if an environment variable is either unset or set to the empty string?

空扰寡人 提交于 2019-12-04 05:48:16

There is probably a nicer way, but you can use eval to delay the execution:

if ($?HAPPYVAR && {eval 'test ! -z $HAPPYVAR'}) then
    ... blah...
else if ($?SADVAR && {eval 'test ! -z $SADVAR'}) then
    ... more blah ...
endif

This seems to work for your needs.

If test doesn't work or you, this will work too:

if ($?HAPPYVAR && { eval 'if ($HAPPYVAR == "") exit 1' }) then

Ah, csh.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!