Search code examples
bashexitshebang

Display exit status code when using bash shebang option -e


Using the following shebang for my bash script:

#!/bin/bash -e

I would like the script to display the exit code whenever it exits upon non-zero status. How can I do this?


Solution

  • Add this to your script:

    trap 'echo $?' EXIT