现在我在脚本中使用这个:
set -euxo pipefail
如果管道中有错误,这将使bash脚本立即失败。
当我离开这个选项,我的脚本将完全运行,并结束退出0(无错误)。
我想两者兼得。我想结束整个剧本但是
exit 1
;如果管道中有错误的话。
我的剧本是这样的:
#!/bin/bash
set -euxo pipefail
curl --fail --compressed -u "$CREDS" -X GET --header 'Accept: xxx' --header 'Accept-Language: de-DE' 'https://api/call1' | jq -S "." > "output1.json"
curl --fail --compressed -u "$CREDS" -X GET --header 'Accept: xxx' --header 'Accept-Language: de-DE' 'https://api/call2' | jq -S "." > "output2.json"
cat output1.json
cat output2.json
所以我不想退出脚本
call1
失败。如果
呼叫1
失败我想去
call2
以及
cat
在退出脚本之前的命令
exit code 1
.