Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash-使用参数作为循环参数_Bash_Loops - Fatal编程技术网

Bash-使用参数作为循环参数

Bash-使用参数作为循环参数,bash,loops,Bash,Loops,我正在尝试使用bash将多个目录中的多个图像缝合到一个视频中。下面的脚本有效 for f in {0..289}; do convert +append Viewer/$f.png Timeline_Board/$f.png Leaderboard/$f.png Montage/montage$f.png; done cd Montage ffmpeg -f image2 -r 7 -i montage%d.png -vcodec libx264 -crf 22 montage.mkv 这将在

我正在尝试使用bash将多个目录中的多个图像缝合到一个视频中。下面的脚本有效

for f in {0..289}; do convert +append Viewer/$f.png Timeline_Board/$f.png Leaderboard/$f.png Montage/montage$f.png; done
cd Montage
ffmpeg -f image2 -r 7 -i montage%d.png -vcodec libx264 -crf 22 montage.mkv
这将在0.png到289.png之间循环,并按预期将组件缝合在一起。但是,我并不总是知道要转换多少帧。我希望能够使用这样的一行:

for f in {0..$1}; do convert +append Viewer/$f.png Timeline_Board/$f.png Leaderboard/$f.png Montage/montage$f.png; done
在这里,我可以传递一个命令行参数来选择我想要的确切帧数。然而,当我的脚本中有这一行并运行
/convert\u images 289
时,我得到一个错误,说
convert:cannot open image'Viewer/{0..289}.png]:没有这样的文件或目录@error/blob.c/OpenBlob/2675。


看起来bash并没有将我传入的整数解释为循环的参数。如何使bash将变量视为循环的数字?

如果您的shell是bash,请使用C-style
for
循环:

for ((f=0; f<289; f++)); do
  ...
done

for((f=0;f)这是一个陷阱#33:这叫做支架扩展?我想我今天学到了一些东西,谢谢。这本身并不是对所问问题的回答,而是((f=0;f)的