687 shaares
3 liens privés
3 liens privés
Best practices shell, to improve :
When printing error messages, please redirect to stderr.
Use echo 'Something unexpected happened' >&2 for this.
And also :
Use set -o xtrace, with a check on $TRACE env variable.
For copy-paste: if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi.
This helps in debugging your scripts, a lot. Like, really lot.
People can now enable debug mode, by running your script as TRACE=1 ./script.sh instead of ./script.sh.