- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果 glob 模式不匹配任何文件,bash
将只返回文字模式:
bash-4.1# echo nonexistent-file-*
nonexistent-file-*
bash-4.1#
您可以通过设置 nullglob
shell 选项来修改默认行为,这样如果没有匹配项,您将得到一个空字符串:
bash-4.1# shopt -s nullglob
bash-4.1# echo nonexistent-file-*
bash-4.1#
那么 ash
中是否有等效的选项?
bash-4.1# ash
~ # echo nonexistent-file-*
nonexistent-file-*
~ # shopt -s nullglob
ash: shopt: not found
~ #
最佳答案
对于没有 nullglob
的 shell,例如 ash 和 dash:
IFS="`printf '\n\t'`" # Remove 'space', so filenames with spaces work well.
# Correct glob use: always use "for" loop, prefix glob, check for existence:
for file in ./* ; do # Use "./*", NEVER bare "*"
if [ -e "$file" ] ; then # Make sure it isn't an empty match
COMMAND ... "$file" ...
fi
done
来源:Filenames and Pathnames in Shell: How to do it correctly ( cached )
关于bash - ash 是否具有与 bash 的 'nullglob' 选项等效的选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4839214/
我可以创建一个数组,然后从这个数组中删除 $ foo=(a b c) $ unset foo[0] $ echo ${foo[*]} b c 但是,如果设置了 nullglob,那么我无法从数组中删除
我发现 shopt -s nullglob 显然禁用了文件和目录的制表符完成,而 shopt -u nullglob 恢复了它。为什么目录的制表符补全显然依赖于未设置 nullglob? 我在 Deb
当我在 bash 中设置 nullglob 时: shopt -s nullglob 然后声明一个关联数组: declare -A arr=( [x]=y ) 我无法取消设置数组中的特定键: unse
在 bash 中,如果你这样做: mkdir /tmp/empty array=(/tmp/empty/*) 你发现 array 现在有一个元素,"/tmp/empty/*",而不是你想要的零。值得庆
如果 glob 模式不匹配任何文件,bash 将只返回文字模式: bash-4.1# echo nonexistent-file-* nonexistent-file-* bash-4.1# 您可以通
我是一名优秀的程序员,十分优秀!