1
这块bash代码在存在多个文件夹时不显示文件夹名称。在bash中打印文件夹名称
#!/bin/bash
for file in .; do
if [ -d $file ]; then
echo $file
fi
done
输出只有.
你能解释一下为什么吗?
这块bash代码在存在多个文件夹时不显示文件夹名称。在bash中打印文件夹名称
#!/bin/bash
for file in .; do
if [ -d $file ]; then
echo $file
fi
done
输出只有.
你能解释一下为什么吗?
它将.
作为大小为1的数组读取并打印给您。使用这样的事情,而不是:
for file in `ls`; do
if [ -d $file ]; then
echo $file
fi
done
[不解析'ls'(http://mywiki.wooledge.org/ParsingLs),使用水珠代替(即'在*文件; do') –