我正在尝试使用bash脚本来批量执行现有的包。每次执行的输入都需要两个输入文件。我可以使用常规名称或将每对放在自己的子目录中,以确保每对保持在一起。我有点零碎,但没有任何东西绕过两个文件或进入一个子目录,做了一些事情,向上移动并在下一个子目录上重复。
这将在包含该对文件的单个目录上执行我想要的操作(每个文件对的名称为ABC10f.txt
和ABC10r.txt
):
#!/bin/bash
#
f=$(ls *f.txt)
echo "forward -> $f"
i=$(ls *r.txt)
echo "reverse -> $i";
/path/to/package [options] $f $i;
以下将循环遍历我的主目录中的每个子目录,但只执行我到达最后一个目录时的所有子目录(注意:我用helloworld.sh
测试它 - 我想如果我能得到它列出每个子目录并回显“你好世界”之后每一个我要去做我想要的事情;而是我得到一个所有子目录的列表,然后是一个“hello world”):
#!/bin/bash
#
myCommand=/path/to/scripts/helloworld.sh
for d in ./; do
find * -maxdepth 1 -type d
cd $d
echo $PWD
exec "$myCommand"
done
将这些放在一起有点帮助?
答案 0 :(得分:2)
让您的helloworld.sh
看起来像:
#!/bin/bash
for f in *f.txt; do
r="${f/f.txt/r.txt}"
echo " f: $f"
echo " r: $r"
/path/to/package [options] "$f" "$r";
done
你的第二次贿赂:
#!/bin/bash
# '*/' pattern matches all of the subdirectories in the current directory
for d in */; do
# doing any actions in a subshell ()
(cd "$d" && echo "$(pwd)" && bash /path/to/scripts/helloworld.sh)
done