【发布时间】:2019-06-24 12:57:42
【问题描述】:
当我在 bash 中设置 nullglob 时:
shopt -s nullglob
然后声明一个关联数组:
declare -A arr=( [x]=y )
我无法取消设置数组中的特定键:
unset arr[x]
echo ${#arr[@]} # still 1
但是,取消设置 nullglob 会使此操作按我的预期工作:
shopt -u nullglob
unset arr[x]
echo ${#arr[@]} # now it's 0; x has been removed
这里发生了什么?我不明白 shell globbing 与这种情况有何关系。我已经在 bash 4.4.19 和 5.0.0 上对此进行了测试。
【问题讨论】:
-
这与nullglob and arrays非常相似
-
见
echo unset arr[x]。
标签: bash associative-array glob quotes shopt