| 1 | #!/usr/bin/env bash
 | 
| 2 | #
 | 
| 3 | # Demo of line numbers, inspired by:
 | 
| 4 | #
 | 
| 5 | # http://lists.gnu.org/archive/html/bug-bash/2016-12/msg00119.html
 | 
| 6 | #
 | 
| 7 | # TODO: would be nice to move into test/gold, but OSH doesn't have the ERR trap
 | 
| 8 | # yet
 | 
| 9 | 
 | 
| 10 | # This doesn't appear necessary:
 | 
| 11 | #shopt -s extdebug
 | 
| 12 | 
 | 
| 13 | main() {
 | 
| 14 |   echo "line number in function: $LINENO"
 | 
| 15 |   trap 'echo line number in trap handler: $LINENO' ERR
 | 
| 16 |   # Start a subshell and exit, which invokes the trap handler.  It uses the function line number?
 | 
| 17 |   # Subshell doesn't have line number attached.
 | 
| 18 |   (exit 17)
 | 
| 19 | 
 | 
| 20 |   # This uses the command line number.
 | 
| 21 |   #$(exit 17)
 | 
| 22 | }
 | 
| 23 | 
 | 
| 24 | main
 | 
| 25 | echo "line number at top level: $LINENO"
 | 
| 26 | 
 |