如何使用循环下载 1945 年到 2020 年的最佳轨道 JTWC 数据文件?
How to download the best track JTWC data files from 1945 to 2020 using loop?
我想从 1945 到 2020 使用循环从 URL 下载数据文件,URL 中只有一个数字变化,
URL 如下所示
https://www.metoc.navy.mil/jtwc/products/best-tracks/1945/1945s-bio/bio1945.zip
https://www.metoc.navy.mil/jtwc/products/best-tracks/1984/1984s-bio/bio1984.zip
https://www.metoc.navy.mil/jtwc/products/best-tracks/2020/2020s-bio/bio2020.zip
我尝试了下面的代码,但它抛出了一个错误
for i in {1945..2020}
do
wget "https://www.metoc.navy.mil/jtwc/products/best-tracks/$i/$is-bio/bio$i.zip"
done
我确实稍微修改了你的代码
for i in {1945..1947}
do
echo "https://www.metoc.navy.mil/jtwc/products/best-tracks/$i/$is-bio/bio$i.zip"
done
当运行它输出
https://www.metoc.navy.mil/jtwc/products/best-tracks/1945/-bio/bio1945.zip
https://www.metoc.navy.mil/jtwc/products/best-tracks/1946/-bio/bio1946.zip
https://www.metoc.navy.mil/jtwc/products/best-tracks/1947/-bio/bio1947.zip
请注意,第一个不是您所期望的 https://www.metoc.navy.mil/jtwc/products/best-tracks/1945/1945s-bio/bio1945.zip
- 第二个 $i
没有按预期工作,因为它后面是 s
它被理解为变量 is
未定义。将变量名括在{
}
中以避免混淆,此代码
for i in {1945..1947}
do
echo "https://www.metoc.navy.mil/jtwc/products/best-tracks/${i}/${i}s-bio/bio${i}.zip"
done
当运行输出
https://www.metoc.navy.mil/jtwc/products/best-tracks/1945/1945s-bio/bio1945.zip
https://www.metoc.navy.mil/jtwc/products/best-tracks/1946/1946s-bio/bio1946.zip
https://www.metoc.navy.mil/jtwc/products/best-tracks/1947/1947s-bio/bio1947.zip
符合您给出的示例。现在您可以使用 wget
替换 echo
或使用 echo
将代码输出保存到名为 say urls.txt
的文件中,然后利用 wget
的 -i
选项]如下
wget -i urls.txt
注意:为简洁起见,我使用 1945..1947
代替 1945..2020
直接成功了,感谢@Daweo
for i in {1945..2020}
do
wget "https://www.metoc.navy.mil/jtwc/products/best-tracks/${i}/${i}s-bio/bio${i}.zip"
done
我想从 1945 到 2020 使用循环从 URL 下载数据文件,URL 中只有一个数字变化, URL 如下所示 https://www.metoc.navy.mil/jtwc/products/best-tracks/1945/1945s-bio/bio1945.zip https://www.metoc.navy.mil/jtwc/products/best-tracks/1984/1984s-bio/bio1984.zip https://www.metoc.navy.mil/jtwc/products/best-tracks/2020/2020s-bio/bio2020.zip
我尝试了下面的代码,但它抛出了一个错误
for i in {1945..2020}
do
wget "https://www.metoc.navy.mil/jtwc/products/best-tracks/$i/$is-bio/bio$i.zip"
done
我确实稍微修改了你的代码
for i in {1945..1947}
do
echo "https://www.metoc.navy.mil/jtwc/products/best-tracks/$i/$is-bio/bio$i.zip"
done
当运行它输出
https://www.metoc.navy.mil/jtwc/products/best-tracks/1945/-bio/bio1945.zip
https://www.metoc.navy.mil/jtwc/products/best-tracks/1946/-bio/bio1946.zip
https://www.metoc.navy.mil/jtwc/products/best-tracks/1947/-bio/bio1947.zip
请注意,第一个不是您所期望的 https://www.metoc.navy.mil/jtwc/products/best-tracks/1945/1945s-bio/bio1945.zip
- 第二个 $i
没有按预期工作,因为它后面是 s
它被理解为变量 is
未定义。将变量名括在{
}
中以避免混淆,此代码
for i in {1945..1947}
do
echo "https://www.metoc.navy.mil/jtwc/products/best-tracks/${i}/${i}s-bio/bio${i}.zip"
done
当运行输出
https://www.metoc.navy.mil/jtwc/products/best-tracks/1945/1945s-bio/bio1945.zip
https://www.metoc.navy.mil/jtwc/products/best-tracks/1946/1946s-bio/bio1946.zip
https://www.metoc.navy.mil/jtwc/products/best-tracks/1947/1947s-bio/bio1947.zip
符合您给出的示例。现在您可以使用 wget
替换 echo
或使用 echo
将代码输出保存到名为 say urls.txt
的文件中,然后利用 wget
的 -i
选项]如下
wget -i urls.txt
注意:为简洁起见,我使用 1945..1947
代替 1945..2020
直接成功了,感谢@Daweo
for i in {1945..2020}
do
wget "https://www.metoc.navy.mil/jtwc/products/best-tracks/${i}/${i}s-bio/bio${i}.zip"
done