本文介绍了bash脚本 - 遍历查找的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有,我需要遍历find命令的输出中的每行一个bash脚本,但现在看来,我遍历从find命令每个单词(分隔空间)。我的脚本看起来像这样至今:
I have a bash script in which I need to iterate over each line of the ouput of the find command, but it appears that I am iterating over each Word (space delimited) from the find command. My script looks like this so far:
folders=`find -maxdepth 1 -type d`
for $i in $folders
do
echo $i
done
我希望这给像输出:
I would expect this to give output like:
./dir1 and foo
./dir2 and bar
./dir3 and baz
但我insted的获得输出是这样的:
But I am insted getting output like this:
./dir1
and
foo
./dir2
and
bar
./dir3
and
baz
我在做什么错在这里?
What am I doing wrong here?
推荐答案
找到
,你可以使用一个简单的模式遍历子目录:
Since you aren't using any of the more advanced features of find
, you can use a simple pattern to iterate over the subdirectories:
for i in ./*/; do
echo "$i"
done
这篇关于bash脚本 - 遍历查找的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!