相关疑难解决方法(0)

如何判断字符串是否未在bash shell脚本中定义?

如果我想检查空字符串,我会这样做

[ -z $mystr ]
Run Code Online (Sandbox Code Playgroud)

但是,如果我想检查变量是否已定义呢?或者bash脚本没有区别?

string bash shell scripting null

149
推荐指数
6
解决办法
17万
查看次数

如何检查我的Bash脚本中是否存在关联数组元素?

我有一系列动物:

declare -A animals=()
animals+=([horse])
Run Code Online (Sandbox Code Playgroud)

我想检查动物是否存在:

if [ -z "$animals[horse]"]; then
    echo "horse exists";
fi
Run Code Online (Sandbox Code Playgroud)

但这不起作用.

bash

10
推荐指数
3
解决办法
1万
查看次数

标签 统计

bash ×2

null ×1

scripting ×1

shell ×1

string ×1