gpt4 book ai didi

linux - 多次运行脚本并将输出保存在多个文件夹中

转载 作者:太空宇宙 更新时间:2023-11-04 12:01:54 24 4
gpt4 key购买 nike

我正在尝试在多个文件夹中运行一个脚本,它调用:一个软件,两个自动创建一个文件夹作为输出的输入文件(在输入文件夹中),例如:

./soft -in1 input1 -in2 input2

此外,我有多个文件夹,如下所示:

├── Folder1
│ ├── input1.in1
│ ├── input1.in2
│ ├── soft.py
├── Folder2
│ ├── input2.in1
│ ├── input2.in2
│ ├── soft.py
├── script.sh

所以,我想做两个过程:

首先,递归运行脚本(在所有文件夹中),其次,在每个文件夹中重复运行“X”次脚本。我让这个脚本递归运行。

但是我在尝试运行重复时遇到了问题。我尝试使用 seq 命令,但软件 ./soft 在每次重复时重写输出。因此,我需要将输出保存在包含每次重复次数的文件夹中(例如\out_Folder1_rep1;\out_Folder1_rep2;\out_Folder1_rep3)。

我之前需要为每次重复创建输出文件夹吗?。有人可以帮助我吗?

for dir in */; do
for r in in1; do
glob=*.${r}
"./soft" -in1 "$dir"/$glob -in2 "$dir"/$(basename -s .tpl $glob).in2 ;
done
done

最佳答案

First, run the script recursively (in all folders), and second, run 'X' repetitions of the script in each folde. I got this script to run recursively.

不是进行递归,而是首先读取根文件夹中所有文件夹的列表,然后“更改目录”到文件夹列表中的每个条目,然后执行您的脚本。

请在下面找到示例代码:

#!/bin/sh

if [ ! -z "${1}" ];
then
DIR_LIST=$(ls -d "${1}/*")
for dir in "${DIR_LIST}";
do
cd ${dir}
# run your script here
done
fi

关于linux - 多次运行脚本并将输出保存在多个文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52087838/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com