如何编写一个bash脚本,通过parent_directory中的每个目录,并在每个目录中执行一个命令。
目录结构如下:
parent_directory (name could be anything – doesnt follow a pattern)
- 001 (directory names follow this pattern)
- 0001.txt (filenames follow this pattern)
- 0002.txt
- 0003.txt
- 002
- 0001.txt
- 0002.txt
- 0003.txt
- 0004.txt
- 003
- 0001.txt
the number of directories is unknown.
您可以执行以下操作,当前当前目录为parent_directory:
原文链接:https://www.f2er.com/bash/391790.htmlfor d in [0-9][0-9][0-9] do ( cd $d && your-command-here ) done
(和)创建一个subshell,所以当前目录不会在主脚本中更改。