【发布时间】:2019-08-28 10:43:53
【问题描述】:
我在使用 shell 执行 CURL 命令时遇到了一个问题。问题是我想获取 curl 命令执行的状态。
我的命令是:
location=curl https://invvvv.usvvv.com/agg/tari?uswg-key=8e3eedhhhh4a9a370605637 --output output.zip --proxy proxy-az.azure.ghop.fguiop.com:8080
问题是如果成功,那么我将在 ${location} 变量中获得一个位置,这很好。但是如果 CURL 执行失败,我不会在变量中获得任何值(只有空值)。
我的问题是如何获取 curl 命令执行的状态,我尝试过使用 if [ $? -eq 0 ],但对于失败也显示 $?为 0。
如何获取 curl 命令的状态?请帮忙
【问题讨论】:
-
if location=$(curl --fail ...); then ...do the success thing...; else ...do the failure thing...; fi -
如果我的 curl 成功,那么它将下载 zip 文件 output.zip.... 否则需要一个机制