How to tell if a string is not defined in a Bash shell script

后端 未结 12 2168
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 04:42

If I want to check for the null string I would do

[ -z $mystr ]

but what if I want to check whether the variable has been defined at all? O

12条回答
  •  情歌与酒
    2020-12-02 05:17

    call set without any arguments.. it outputs all the vars defined..
    the last ones on the list would be the ones defined in your script..
    so you could pipe its output to something that could figure out what things are defined and whats not

提交回复
热议问题