bash 中 aws cli 的错误处理不会导致其退出

edo*_*ocx 6 bash aws-cli

我有一个 bash 脚本,它与 aws listobject 命令一起运行一堆东西。最近我们注意到 std err 会有一个错误代码,但脚本不会以非零代码退出。我希望 set -e 应该处理任何命令失败,但它似乎并没有达到目的。

脚本如下所示:

#!/bin/bash

set -e
# do stuff
aws s3api list-objects --bucket xyz --prefix xyx --output text --query >> files.txt
# do stuff

Error in Stderr :
An error occurred (SlowDown) when calling the ListObjects operation (reached max retries: 4): Please reduce your request rate.
Run Code Online (Sandbox Code Playgroud)

目标:我希望 bash 脚本在遇到 aws cli 命令问题时失败并退出。我可以添加对 ($?!= 0) 的显式检查,但想知道是否有更好的方法来做到这一点。

Ozr*_*ric 5

对我来说,这成功了:

set -e -o pipefail
Run Code Online (Sandbox Code Playgroud)

@codeforrester 的链接说:

set -o pipefail is a workaround by returning the exit code of the first failed process
Run Code Online (Sandbox Code Playgroud)