fork download
  1. #!/bin/bash
  2.  
  3. set -E
  4. function handle_error {
  5. local retval=$?
  6. local line=$1
  7. echo "Failed at $line: $BASH_COMMAND"
  8. exit $retval
  9. }
  10. trap 'handle_error $LINENO' ERR
  11.  
  12. function fail {
  13. echo "I expect the next line to be the failing line: $((LINENO + 1))"
  14. command_that_fails
  15. }
  16.  
  17. fail
  18.  
Runtime error #stdin #stdout #stderr 0.02s 5316KB
stdin
Standard input is empty
stdout
I expect the next line to be the failing line: 14
Failed at 14: command_that_fails
stderr
prog.sh: line 14: command_that_fails: command not found