arrays - nullglob 和数组

标签 arrays bash glob shopt

我可以创建一个数组,然后从这个数组中删除

$ foo=(a b c)

$ unset foo[0]

$ echo ${foo[*]}
b c

但是,如果设置了 nullglob,那么我无法从数组中删除

$ shopt -s nullglob

$ foo=(a b c)

$ unset foo[0]

$ echo ${foo[*]}
a b c

最佳答案

unset 'foo[0]'

Bash thinks the var[1] is a glob, doesn't find a file that matches it, and per instruction of nullglob removes it, causing your script to run unset instead of unset var[1] - and nothing gets unset. The correct way to fix this issue is to quote the variable name (and always specify -v explicitly): unset -v 'var[1]'.

§ nullglob

关于arrays - nullglob 和数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15897473/

相关文章:

Java 点线数组超过 65535 字节

git - bash/zsh 提示右对齐显示 Git 存储库数据

java - 一个简短的脚本,用于处理充满文件的目录,一个接一个,维护名称

linux - 从系统编号列表中匹配文本文件

Python-获取文件目录作为用户输入

directory - 具有不同独立主题的 Sphinx 文档

c - glob 的结果是如何排序的?

python - 如何填充和访问 Django ArrayField?

java - 从 Java 数组中调用特定行

java - 有什么方法可以加快java中两个 double 组之间的余弦相似度的计算吗?