为什么我在Bash中的wget导致400 Bad Request错误?

时间:2018-12-29 15:38:36

标签: bash wget

我在文本文件中有此数据:

  

-O BNU-ESM-pr-Historical-19560101-19601231.nc https://dataserver.nccs.nasa.gov/thredds/ncss/bypass/NEX-GDDP/bcsd/historical/r1i1p1/pr/BNU-ESM.ncml?var=pr&north=55&west=72&east=136&south=16&horizStride=1&time_start=1956-01-01T12%3A00%3A00Z&time_end=1960-12-31T12%3A00%3A00Z&timeStride=1

我正在将以下代码用于.sh文件:

#!/bin/bash
while read -r line; do wget $line; done < pr_china.txt

BASH中命令的结果:

ahmad@ahmad:/mnt/c/script_sh_files$ ./pr_china.sh
--2018-12-29 23:10:30--  https://dataserver.nccs.nasa.gov/thredds/ncss/bypass/NEX-GDDP/bcsd/historical/r1i1p1/pr/BNU-ESM.ncml?var=pr&north=55&west=72&east=136&south=16&horizStride=1&time_start=1956-01-01T12%3A00%3A00Z&time_end=1960-12-31T12%3A00%3A00Z&timeStride=1%0D
Resolving dataserver.nccs.nasa.gov (dataserver.nccs.nasa.gov)... 2001:4d0:2418:2800::a99a:9229, 169.154.146.41
Connecting to dataserver.nccs.nasa.gov (dataserver.nccs.nasa.gov)|2001:4d0:2418:2800::a99a:9229|:443... connected.
HTTP request sent, awaiting response... 400 Bad Request
2018-12-29 23:10:33 ERROR 400: Bad Request.

1 个答案:

答案 0 :(得分:0)

在使用pr_china.txt文件之前运行dos2unix。

请参阅:How to remove %0D from end of URL when using wget?