1 | #!/usr/bin/env bash |
2 | # |
3 | # Usage: |
4 | # ./lineno.sh <function name> |
5 | |
6 | set -o nounset |
7 | set -o pipefail |
8 | set -o errexit |
9 | |
10 | # https://unix.stackexchange.com/questions/355965/how-to-check-which-line-of-a-bash-script-is-being-executed |
11 | |
12 | # This is different than LINENO, see gold/xtrace1.sh. |
13 | |
14 | f(){ echo "${BASH_LINENO[-2]}"; } |
15 | |
16 | echo next1 |
17 | f |
18 | |
19 | echo next2 |
20 | f |
21 | |
22 | echo next 3 |
23 | f |