- set +e
- trap - ERR
- yum list installed coreutils 2> /dev/null | grep -q coreutils &> /dev/null
- set -e
- trap 'echo "An error occurred with command: $BASH_COMMAND at line $LINENO"; exit 1' ERR
复制代码 这样用就正常- capture_exit_code (){
- set -e
- trap 'echo "An error occurred with command: $BASH_COMMAND at line $LINENO"; exit 1' ERR
- }
- turn_off_capture_exit_code (){
- echo "成功关闭捕获错误码"
- set +e;
- trap - ERR;
- }
- capture_exit_code
- turn_off_capture_exit_code
- yum list installed coreutils 2> /dev/null | grep -q coreutils &> /dev/null
- capture_exit_code
复制代码 这样用yum list installed coreutils 2> /dev/null | grep -q coreutils &> /dev/null命令还是被捕获退出码
求助,为什么? |