Debug in bash
To run bash scripts in a safer way, here are some tips and usage patterns to debug bash scripts.
command line options
bash -x ## debug bash -n ## test syntax
set -eexit immediately when a command fails
set -uview undefined variable as error
set -xrun in debug mode
set -o pipefailThis tells the script that if any of the steps (not in a block construction) fail (exit with non-zero), the whole script should halt in place and the script will exit with the failure message of the failed step.
Put them together
set -euxo pipefail
- License under
CC BY-NC 4.0
- Copyright issue feedback
me#imzye.me, replace # with @
- Not all the commands and scripts are tested in production environment, use at your own risk
- No privacy information is collected here