这段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
关于linux - 在 bash 中打印文件夹名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13094165/