请注意,我读过如下条目
For loop for files in multiple folders - bash shell
他们要求的是一件截然不同的事情。
我想按排序顺序遍历存在于两个目录中的任何一个目录中的文件名。文件中可能包含空格。
假设我有:
1/
a
a c b
b
c
2/
a
d
我想循环:'a','a c b','b','c','d'。
我已尝试执行以下操作:
for fname in $((ls -1 -f -A "${dir1}"; ls -1 -f -A "${dir2}")|sort --unique); do
echo "testing ${fname}"
done
结果是
testing .
testing ..
testing a
testing a
testing c
testing b
testing b
testing c
testing d
无论什么原因,我都会得到“.”和“…”我试图排除的条目
-A
,并且文件“a c b”被分解为三个字符串。
我试图通过添加
--zero
到
sort
命令,没有任何改变;引用整体
$(ls...|sort)
部分,并导致for循环中的一个条目,该条目接收了整个字符串,其中包含多行,每行都包含filename。