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」)を繰り返します。

また、typebashでは予約語です。代わりに別の変数名(たとえば)を使用してください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

おすすめ記事