Zsh有类似于BASH_LINENO的等价物吗?

3

这个问题提到了如何在Bash函数(以及可能的脚本)中获取行号,但我想知道如何在Zsh中实现。

2个回答

3

zsh 只使用 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.

对于函数来说,LINENO不会显示函数定义所在文件的绝对行号,而是相对于函数开头开始的行数。有没有一种方法可以获取绝对行号呢? - pawamoy
1
@pawamoy 在 PS4 变量中使用 %i 表示相对行号,使用 %I 表示绝对行号。 - pawamoy

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接