This question mentions how to get the line number in a Bash function (and possibly a script as well), but I'd like to know how to do it in Zsh.
Asked
Active
Viewed 750 times
2 Answers
3
zsh
just uses LINENO:
man zshparam
:
LINENO <S> The line number of the current line within the current script, sourced file, or shell function being executed, whichever was started most recently. Note that in the case of shell functions the line number refers to the function as it appeared in the original definition, not necessarily as displayed by the func- tions builtin.

chepner
- 497,756
- 71
- 530
- 681
-
So for functions, LINENO will not display the absolute line number in the file where the function was defined, but the relative number starting from the beginning of the function. Is there a way to get, instead, the absolute line number? – pawamoy May 10 '19 at 16:55
-
1@pawamoy Use `%i` for relative line number, and `%I` for absolute line number in the `PS4` variable. – pawamoy May 10 '19 at 18:44
0
As per @pawamoy's comment, in PS4
, use %I
for the absolute line number.

ivan_pozdeev
- 33,874
- 19
- 107
- 152