Hacker News new | past | comments | ask | show | jobs | submit login

Related, but I use exit traps (or actually ERR traps) to make debugging bash scripts at runtime a little easier. This will print the number of the line of the script that failed along with any error messages from the line that failed. This is useful if for whatever reason your logging system or whatever doesn't capture stderr

```

failure() {

  local lineno="$1"

  local msg="$2"

  echo "Failed at ${lineno}: ${msg}"
}

trap 'failure "$LINENO" "BASH_COMMAND"' ERR

```




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: