gpt4 book ai didi

linux - 使用两个输入执行 for 循环

转载 作者:太空宇宙 更新时间:2023-11-04 05:15:50 25 4
gpt4 key购买 nike

我正在使用 for-loop 在 Linux 中执行我的命令。我在一个输入中有 20 个文件,在另一个输入中有 20 个文件

for f1 in zero-mam-2050-2074*.nc;
do;
f2={avm-mam-1976-2000-tasmax-*.nc};
command $f1 $f2 output;
done

它没有读取第二个输入。

最佳答案

分号:

for f1 in zero-mam-2050-2074*.nc;
do;
f2={avm-mam-1976-2000-tasmax-*.nc};
command $f1 $f2 output;
done

没用。

for f1 in zero-mam-2050-2074*.nc
do
f2={avm-mam-1976-2000-tasmax-*.nc}
command $f1 $f2 output
done

3号线有问题。你想让我做什么?创建一个数组?

for f1 in zero-mam-2050-2074*.nc
do
f2=(avm-mam-1976-2000-tasmax-*.nc)
command "$f1" "${f2[@]}" output
done

要循环,假设有 20 个文件,匹配模式 f1,并使用假设 20 个文件匹配 f2 来调用每个文件:

for f1 in zero-mam-2050-2074*.nc
do
f2=avm-mam-1976-2000-tasmax-*.nc
command "$f1" $f2 output
done

这将导致 20 个命令调用,滚动通过 f1,但每次调用都使用与 f2 匹配的所有文件。

对于 20x20 比赛,您将使用第二个循环。适合我硬盘上的文件模式:

for f1 in file1*; do  f2=sample.*;  echo command "$f1" $f2* output; done
command file1 sample.conf sample.go sample.log sample.xml output
command file1.txt sample.conf sample.go sample.log sample.xml output
command file1nums sample.conf sample.go sample.log sample.xml output

您当然会使用您的模式,并在测试后删除回声

关于linux - 使用两个输入执行 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49666517/

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