巴什与通配符和隐藏文件循环 [英] Bash for loop with wildcards and hidden files
问题描述
只需知晓一个简单的shell脚本和有点糊涂了:
Just witting a simple shell script and little confused:
下面是我的脚本:
% for f in $FILES; do echo "Processing $f file.."; done
命令:
ls -la | grep bash
生产:
% ls -a | grep bash
.bash_from_cshrc
.bash_history
.bash_profile
.bashrc
在
FILES=".bash*"
我得到相同的结果(不同的格式)作为LS -a。然而,当
I get the same results (different formatting) as ls -a. However when
FILES="*bash*"
我得到这样的输出:
I get this output:
Processing *bash* file..
这不是预期的输出,而不是我所期望的。难道我不允许有在文件名开头外卡?是个 。在文件名特殊莫名其妙的开始?
This is not the expected output and not what I expect. Am I not allowed to have a wild card at the beginning of the file name? Is the . at the beginning of the file name "special" somehow?
设置
FILES="bash*"
也不起作用。
推荐答案
FILES =庆典*
工作,因为隐藏文件名以<$ C $开始C>。
FILES=".bash*"
works because the hidden files name begin with a .
FILES =庆典*
不起作用,因为隐藏文件名以。
不是一个开始 b
FILES="bash*"
doesn't work because the hidden files name begin with a .
not a b
FILES =* *庆典
不起作用,因为在字符串的开头的 *
通配符忽略隐藏文件。
FILES="*bash*"
doesn't work because the *
wildcard at the beginning of a string omits hidden files.
这篇关于巴什与通配符和隐藏文件循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!