[Bug 235589] sh(1): LINENO is unset in shell arithmetic

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Sun Sep 8 21:29:43 UTC 2019


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=235589

--- Comment #3 from Jilles Tjoelker <jilles at FreeBSD.org> ---
I like that this does not slow down the main execution loop much, since it only
does the conversion from integer to string when LINENO is referenced.

This part could be slightly less magic by making a fixed struct var for LINENO
(like HISTSIZE, IFS, MAIL, MAILPATH, etc.). This fixed struct can also point to
a sufficiently large buffer "LINENO=1\0\0\0\0\0\0\0\0\0\0".

I would like to see this new mechanism used instead of the old VSLINENO
mechanism (so there aren't two separate mechanisms for $LINENO and
$((LINENO))).

Given that this will subtly change LINENO values anyway (try expanding LINENO
twice in different lines of a word spanning multiple lines), I think it would
make more sense to make it more like other shells do, reading the line number
at the start of a command containing expansions (NCMD/NCASE/NFOR).

With this, it should be possible to set PS4='$LINENO+ ' and see the script's
line numbers in set -x output.

You can compare
https://git.kernel.org/pub/scm/utils/dash/dash.git/commit/?id=5bb39bb1995cb12d8da76b1d482df9be1acc2eb4
which is a similar implementation for dash (another Almquist variant) but I
don't think there will be much benefit in copying code from there.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list