Bug 235589 - sh(1): LINENO is unset in shell arithmetic
Summary: sh(1): LINENO is unset in shell arithmetic
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 12.0-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
Depends on:
Reported: 2019-02-07 23:01 UTC by Martijn Dekker
Modified: 2019-08-02 02:42 UTC (History)
1 user (show)

See Also:

A potential fix (2.72 KB, patch)
2019-08-02 02:42 UTC, me
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martijn Dekker 2019-02-07 23:01:32 UTC
In sh(1), the LINENO variable (currently executed line number) is always zero when it is read as part of a shell arithmetic expression.

For instance:

$ echo $LINENO $((LINENO)) $(($LINENO))
108 0 108

Expected: 3 times "108" (or whatever the current line number is)

Note that $(($LINENO)) does work because it expands LINENO as a normal shell expansion before invoking the arithmetic subsystem. However, $((LINENO)) should be equivalent as it is for all other variables.

Another manifestation of the bug is:

$ set -u
$ echo $((LINENO))
-sh: arithmetic expression: variable not set: "LINENO"
Comment 1 me 2019-08-02 02:42:15 UTC
Created attachment 206211 [details]
A potential fix

This is my first attempt at submitting a patch to FreeBSD. I'm not sure if it's good practice to submit a potential patch directly to the bug report or to first have it reviewed elsewhere such as the mailing lists.