灰烬是否与bash的’nullglob’选项相当?
发布时间:2020-12-15 21:29:49 所属栏目:安全 来源:网络整理
导读:如果glob模式与任何文件都不匹配,bash将只返回文字模式: bash-4.1# echo nonexistent-file-*nonexistent-file-*bash-4.1# 您可以通过设置nullglob shell选项来修改默认行为,这样如果没有匹配,则会得到一个空字符串: bash-4.1# shopt -s nullglobbash-4.1#
如果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# 灰烬中有相同的选择吗? bash-4.1# ash ~ # echo nonexistent-file-* nonexistent-file-* ~ # shopt -s nullglob ash: shopt: not found ~ # 解决方法
对于没有nullglob的shell,例如ash和dash:
IFS="`printf 'nt'`" # 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) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读