如何使部分URL在cURL中同时增加?

jor*_*dan 3 shell terminal command-line curl

我正在使用cURL将文件下载到本地文件夹。我正在使用的命令如下所示:

curl -O http://example.com/example/file[001-030]_file_[1-30]_eng.ext 
Run Code Online (Sandbox Code Playgroud)

我希望数字同时增加(“ file001_file_1_eng.ext”),以便它们匹配。相反,这就像嵌套循环一样工作,该命令将一堆空文件与现有文件一起写入该文件夹。所以我得到:

file001_file_1_eng.ext
file001_file_2_eng.ext <--- file doesn't exist
file001_file_3_eng.ext <--- file doesn't exist
Run Code Online (Sandbox Code Playgroud)

等等...

因此,我想知道如何使它们以正确的方式递增。

我正在寻找这个输出:

example.com/example/file008_file_1_eng.text 
example.com/example/file009_file_2_eng.text
example.com/example/file010_file_3_eng.text 
example.com/example/file011_file_4_eng.text 
example.com/example/file012_file_5_eng.text 
example.com/example/file013_file_6_eng.text 
example.com/example/file014_file_7_eng.text 
example.com/example/file015_file_8_eng.text 
example.com/example/file016_file_9_eng.text ... and so on. 
Run Code Online (Sandbox Code Playgroud)

jco*_*ado 5

我认为您可能想使用for循环:

#!/bin/bash
for i in {0..30}; do
    printf -v url "http://example.com/example/file%03d_file_%d_eng.text" $i $i
    curl -O $url
done
Run Code Online (Sandbox Code Playgroud)

通过此循环,您应该获得的URL是以下URL:

http://example.com/example/file000_file_0_eng.text
http://example.com/example/file001_file_1_eng.text
http://example.com/example/file002_file_2_eng.text
http://example.com/example/file003_file_3_eng.text
http://example.com/example/file004_file_4_eng.text
http://example.com/example/file005_file_5_eng.text
http://example.com/example/file006_file_6_eng.text
http://example.com/example/file007_file_7_eng.text
http://example.com/example/file008_file_8_eng.text
http://example.com/example/file009_file_9_eng.text
http://example.com/example/file010_file_10_eng.text
http://example.com/example/file011_file_11_eng.text
http://example.com/example/file012_file_12_eng.text
http://example.com/example/file013_file_13_eng.text
http://example.com/example/file014_file_14_eng.text
http://example.com/example/file015_file_15_eng.text
http://example.com/example/file016_file_16_eng.text
http://example.com/example/file017_file_17_eng.text
http://example.com/example/file018_file_18_eng.text
http://example.com/example/file019_file_19_eng.text
http://example.com/example/file020_file_20_eng.text
http://example.com/example/file021_file_21_eng.text
http://example.com/example/file022_file_22_eng.text
http://example.com/example/file023_file_23_eng.text
http://example.com/example/file024_file_24_eng.text
http://example.com/example/file025_file_25_eng.text
http://example.com/example/file026_file_26_eng.text
http://example.com/example/file027_file_27_eng.text
http://example.com/example/file028_file_28_eng.text
http://example.com/example/file029_file_29_eng.text
http://example.com/example/file030_file_30_eng.text
Run Code Online (Sandbox Code Playgroud)