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

Clay Daniels Jr. clay.daniels.jr at gmail.com
Mon Jul 15 07:25:54 UTC 2019


Paco, I got curious about $LINENO & noticed that it is only available in
sh, but not csh nor tcsh:

clay at bsd13:/usr/home/clay $ echo $SHELL
/bin/sh
clay at bsd13:/usr/home/clay $ echo $LINENO
2
clay at bsd13:/usr/home/clay $ cat /etc/shells
# $FreeBSD: head/etc/shells 348185 2019-05-23 18:37:05Z bapt $
#
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/sh
/bin/csh
/bin/tcsh
clay at bsd13:/usr/home/clay $ /bin/csh
clay at bsd13:~ % echo $LINENO
LINENO: Undefined variable.
clay at bsd13:~ % /bin/tcsh
clay at bsd13:~ % echo $LINENO
LINENO: Undefined variable.
clay at bsd13:~ % /bin/sh
clay at bsd13:~ $ echo $LINENO $((LINENO)) $(($LINENO))
1 0 1
clay at bsd13:~ $


On Mon, Jul 15, 2019 at 12:11 AM Paco Pascal <me at pacopascal.com> wrote:

> 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
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
>


More information about the freebsd-hackers mailing list