循环对象作为BASH输入shell脚本 [英] looping object as inputs in BASH, SHELL script
本文介绍了循环对象作为BASH输入shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
具有相同名称的多个文件 grid_200001.grb2.nc
只有一个部件发生变化,那就是每月 grid_200010.grb2.nc
。我想同时使用它们作为输入文件的
我所希望达到的一个例子是
FNAME =grid_
一年=2010
一个月=01 02 03 04 05 06 07 08 09 10
EXT =GRB2
最终=NC为((Y = $一年; Y< = $一年; Y ++));
做
在$ m月
做 IFILE = $ FNAME $ Y $ M,$分机$结束 >>合并$ ifile的$ ifile的... OFILE
所需的命令的例子,我想有是
>>合并grid_200001.grb2.nc grid_200002.grb2.nc .... grid_200012.grb2.nc OFILE
我想我所有可用的文件,在同一时间
输入文件输入解决方案
FNAME =grid_
年=({} 2000..2010)
个月=(01 02 03 04 05 06 07 08 09 10)##({01..10})应该是相同的
EXT =GRB2
最终=NC禁用了javascript -s extglob
IFS ='|' EVAL'模式=$ {fname}文件@($ {年[*]})@($ {个月[*]})。$ {EXT} $ {}到底
回声模式= $ {}模式##的好奇心。
文件=($模式)##路径扩展是bash中排序。合并$ {文件[@]}OFILE
multiple files with the same name grid_200001.grb2.nc
with only one components changing and that is the month grid_200010.grb2.nc
. I would like to use them all simultaneously as input files
An example of what I am hoping to achieve is
fname="grid_"
year="2010"
month="01 02 03 04 05 06 07 08 09 10"
ext="grb2"
end="nc"
for((y=$year;y<=$year;y++));
do
for m in $month
do
ifile=$fname$y$m.$ext.$end
>>merge $ifile $ifile ... ofile
example of the desired command i would like to have is
>> merge grid_200001.grb2.nc grid_200002.grb2.nc ....grid_200012.grb2.nc ofile
I would like all the files i have available as input files inputs at the same time
解决方案
fname="grid_"
years=({2000..2010})
months=(01 02 03 04 05 06 07 08 09 10) ## ({01..10}) should be the same
ext="grb2"
end="nc"
shopt -s extglob
IFS='|' eval 'pattern="${fname}@(${years[*]})@(${months[*]}).${ext}.${end}"'
echo "pattern = ${pattern}" ## for curiosity.
files=($pattern) ## pathname expansion is sorted in Bash.
merge "${files[@]}" ofile
这篇关于循环对象作为BASH输入shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文