无法使用curl for循环下载数据

无法使用curl for循环下载数据

我正在尝试从以下链接下载数据

export ICTP_DATASITE='http://clima-dods.ictp.it/data/Data/RegCM_Data/EIN15/1990/'

这些是代码:

for type in "air hgt rhum uwnd vwnd"
do
    for hh in "00 06 12 18"
    do
       curl -o ${type}.1990.${hh}.nc \
       ${ICTP_DATASITE}/EIN15/1990/${type}.1990.${hh}.nc
    done
done

但它没有下载,我收到以下错误消息

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: hgt
curl: (6) Could not resolve host: rhum
curl: (6) Could not resolve host: uwnd
curl: (6) Could not resolve host: vwnd.1990.00
curl: (7) Could not resolve host: vwnd.1990.00
curl: (7) Could not resolve host: vwnd.1990.00
curl: (6) Could not resolve host: 18.nc
curl: (3) <url> malformed
curl: (6) Could not resolve host: hgt
curl: (6) Could not resolve host: rhum
curl: (6) Could not resolve host: uwnd
curl: (6) Could not resolve host: vwnd.1990.00
curl: (7) Could not resolve host: vwnd.1990.00
curl: (7) Could not resolve host: vwnd.1990.00
curl: (6) Could not resolve host: 18.nc

你能帮我么。

答案1

从行中的循环项中删除双引号for- 您正在迭代单个字符串(“air hgt rhum uwnd vwnd”和“00 06 12 18”),而不是项目列表。

另外,type是 bash 中的保留字。使用另一个变量名称,例如t, 代替。

最后,在使用变量时应始终用双引号引起来。

把所有这些放在一起,试试这个:

export ICTP_DATASITE='http://clima-dods.ictp.it/data/Data/RegCM_Data/EIN15/1990/'

for t in air hgt rhum uwnd vwnd; do
    for hh in 00 06 12 18; do
       curl -o "${t}.1990.${hh}.nc" \
       "${ICTP_DATASITE}/EIN15/1990/${t}.1990.${hh}.nc"
    done
done

相关内容