我有一个像这样的bash代码:
set -x
status=$(curl --write-out '%{http_code}' $nb_url)
echo "got status code = $status"
这是我得到的调试输出:
++ curl --write-out '%{http_code}' 'https://myurl:54516/?token=89835a6dd0793eda'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed connect to myurl:54516; Connection refused
+ status=000
因此状态设置为000但回显从不执行。你知道为什么吗?
答案 0 :(得分:0)
问题是我有一套' set -e'在我的脚本
set -e # <-- Remove this line it works
set -x
status=$(curl --write-out '%{http_code}' $nb_url)
echo "got status code = $status"