我有一个简单的代码:
HEADERS_FILE_NAME=headers.txt
FILE=body.xml
echo "start getting"
curl -D $HEADERS_FILE_NAME -o $FILE --fail http://<SOMEURLHERE>:7001/articles?indexingInfoId=4&format=xml 2>/dev/null
echo "end getting"
输出为:
start getting
end getting
root@prod_l04:~# % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 166M 0 166M 0 0 14.5M 0 --:--:-- 0:00:11 --:--:-- 34.9M
问题:如何让curl等待收到响应后,然后执行“echo “end getting”
”
最佳答案
URL 不带引号并包含与号 (&
);因此 shell 将该行读取为:
curl -D $HEADERS_FILE_NAME -o $FILE --fail http://:7001/articles?indexingInfoId=4
&format=xml 2>/dev/null
and thus runs curl
at the background. Since format=xml 2>/dev/null
is a valid command line you're not getting an error from it.
See
Bash Reference Manual § Quoting and,
Bash Reference Manual § Lists
for further information.
And here is a working, safe version of your script with proper quotation:
HEADERS_FILE_NAME='headers.txt'
FILE='body.xml'
echo 'start getting'
curl -D "$HEADERS_FILE_NAME" -o "$FILE" --fail 'http://<SOMEURLHERE>:7001/articles?indexingInfoId=4&format=xml' 2>/dev/null
echo 'end getting'
关于bash - 如何让curl等待响应然后继续执行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58283516/