相关疑难解决方法(0)

Bash脚本 - 迭代find的输出

我有一个bash脚本,我需要遍历find命令的输出的每一行,但看起来我正在从find命令迭代每个Word(空格分隔).到目前为止我的脚本看起来像这样:

folders=`find -maxdepth 1 -type d`

for $i in $folders
do
    echo $i
done
Run Code Online (Sandbox Code Playgroud)

我希望这会给出如下输出:

./dir1 and foo
./dir2 and bar
./dir3 and baz
Run Code Online (Sandbox Code Playgroud)

但我得到这样的输出:

./dir1
and
foo
./dir2
and
bar
./dir3
and
baz
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?

linux bash shell scripting

1
推荐指数
2
解决办法
6477
查看次数

标签 统计

bash ×1

linux ×1

scripting ×1

shell ×1