At top of your bash script add this after `#!/bin/bash` line to aborts the script immediately and add robustness to your script
```
set -euo pipefail
```

Use the following to trap error and show line number where your script failed to debut at run time or development time:
```
_failed() {
echo "$0 - Script failed at line $1"
}

# Trap the ERR
trap '_failed $LINENO' ERR
```

See `man bash` or `help set` for more.

@nixCraft Ah, the global pipefail.
The indicator of a bash novice or slop-generated script...

Indiscriminate "set -euo pipefail" - especially in scripts that have no pipes whatsoever - is one of the best hints that somebody generated the script and did not understand it :)

https://mywiki.wooledge.org/BashPitfalls#pipefail

BashPitfalls - Greg's Wiki

@richlv @nixCraft FWIW I understand the downsides of `set -euo pipefail` but I start every script with it by default. Then I disable parts or get more sophisticated if I need to. The idea is that basically I'm changing the default behavior of bash, to be more like I usually want it to be.