What's the expected behavior of LINENO from /bin/sh?

Paco Pascal me at pacopascal.com
Mon Jul 15 05:10:45 UTC 2019


Hello,

I'm new at attempting to contribute to the FreeBSD project. As an
introduction to working on FreeBSD, I started searching the bug
database and settled into bug #235589. If I've made an error in my
approach to the community, just let me know.

I'm not sure what the wisest method is to fix this, given I'm not
familiar with the code-base. Also, it's not clear what the correct
behavior of LINENO should be. FreeBSD's shell treats LINENO differently
than bash. For example,

  cmd='echo $LINENO $((LINENO)) $(($LINENO))'

  f() {
          eval ${cmd}
          echo $LINENO $((LINENO)) $(($LINENO))
  }

  eval ${cmd}
  echo $LINENO $((LINENO)) $(($LINENO))
  f

has the following output in bash,

  8 8 8
  9 9 9
  4 4 4
  5 5 5

while FreeBSD's shell outputs,

  1 0 1
  9 0 9
  1 0 1
  3 0 3 .

The reason for the bug (and difference in behavior) is because LINENO
isn't treated as other variables are; it's value can't be looked up
using lookupvar() from var.c which is what arith() eventually does
when trying to find the value of a variable that isn't preceded by a
"$". 

So, the first thing I need to ask before I go any further is, what's
the expected behavior in the above conditions? 

// Paco


More information about the freebsd-hackers mailing list