只循环遍历子目录
Loop only through subdirs
我有以下目录结构
mkdir -p joe/{0,1}
mkdir -p john/0
tree
.
├── joe
│ ├── 0
│ └── 1
└── john
└── 0
我想为每个条目调用一个程序,在这种情况下,程序应该被调用 3 次,program joe/0
、program joe/1
和 program john/0
如何在纯 bash 脚本中执行此操作?
提前致谢。
遍历./*/*/
.
for arg in ./*/*/; do
program "$arg"
# if you don't want the trailing slash:
# program "${arg%/}"
done
这称为 文件名扩展,并记录在案 here。
我有以下目录结构
mkdir -p joe/{0,1}
mkdir -p john/0
tree
.
├── joe
│ ├── 0
│ └── 1
└── john
└── 0
我想为每个条目调用一个程序,在这种情况下,程序应该被调用 3 次,program joe/0
、program joe/1
和 program john/0
如何在纯 bash 脚本中执行此操作?
提前致谢。
遍历./*/*/
.
for arg in ./*/*/; do
program "$arg"
# if you don't want the trailing slash:
# program "${arg%/}"
done
这称为 文件名扩展,并记录在案 here。