How to avoid a bash script from failing when -e option is set?

前端 未结 3 643
误落风尘
误落风尘 2021-01-03 19:24

I have a bash script with -e option set, which fails the whole script on the very first error.

In the script, I am trying to do an ls on a

3条回答
  •  长发绾君心
    2021-01-03 19:31

    Another option is to use trap to catch the EXIT signal:

    trap 'echo "ls failed" ; some_rescue_action' EXIT
    ls /non_exist
    

提交回复
热议问题