List Info

Thread: $LINENO within functions




$LINENO within functions
user name
2008-05-30 12:27:12
Hi,

SUSv3 says the following about $LINENO:

"Set by the shell to a decimal number representing the
current
sequential line number (numbered starting with 1) within a
script or
function before it executes each command. If the user unsets
or resets
LINENO , the variable may lose its special meaning for the
life of the
shell. If the shell is not currently executing a script or
function, the
value of LINENO is unspecified. This volume of IEEE Std
1003.1-2001
specifies the effects of the variable only for systems
supporting the
User Portability Utilities option."

My initial interpretation of "or function" was
that it means $LINENO
within a function should be relative to the function's
beginning line.
Now I'm not so sure anymore.  Bash release 2.05b changed the
expansion
of $LINENO within functions to absolute numbering, stating
this is
required by POSIX.  But then I wonder about the meaning of
"or
function".  Does it mean functions in interactive
scripts?  Because for
functions in shell scripts the mentioning of both
"script" and
"function" seems redundant.

Stefan
_______________________________________________
freebsd-standardsfreebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-sta
ndards
To unsubscribe, send any mail to
"freebsd-standards-unsubscribefreebsd.org"

Re: $LINENO within functions
country flaguser name
Germany
2008-05-30 13:21:34
Stefan Farfeleder wrote:
 > SUSv3 says the following about $LINENO:
 > 
 > "Set by the shell to a decimal number
representing the current
 > sequential line number (numbered starting with 1)
within a script or
 > function before it executes each command. If the user
unsets or resets
 > LINENO , the variable may lose its special meaning for
the life of the
 > shell. If the shell is not currently executing a
script or function, the
 > value of LINENO is unspecified. This volume of IEEE
Std 1003.1-2001
 > specifies the effects of the variable only for systems
supporting the
 > User Portability Utilities option."
 > 
 > My initial interpretation of "or function"
was that it means $LINENO
 > within a function should be relative to the function's
beginning line.
 > Now I'm not so sure anymore.  Bash release 2.05b
changed the expansion
 > of $LINENO within functions to absolute numbering,
stating this is
 > required by POSIX.  But then I wonder about the
meaning of "or
 > function".  Does it mean functions in interactive
scripts?  Because for
 > functions in shell scripts the mentioning of both
"script" and
 > "function" seems redundant.

When reading the SUSv3 text, my interpretation is the same
as your initial interpretation.  FWIW, Solaris' POSIX shell
(ksh) behaves like FreeBSD's sh, not like bash.  Same for
zsh.  So bash seems to be pretty much alone in its inter-
pretation of SUSv3.

I also think that it should not make a difference whether a
function definition is entered interactively or read from
a script -- $LINENO should always expand to the same value
at the same line number within that function.  It shouldn't
depend on where the function definition comes from.
I think that's what the people from the SUS/POSIX committee
wanted to say.

Therefore my opinion is that FreeBSD's current behaviour is
fine, and bash is wrong.

By the way, SUSv3 also mentions $LINENO in the Shell
Command
Language Rationale (xrat/xcu_chap02) in the explanation of
the $PS4 variable used for debugging with "set
-x":

=== QUOTE ===

   PS4     This variable is used for shell debugging.
           For example, the following script:

 PS4='[$]+ '
 set -x
 echo Hello

           writes the following to standard error:

 [3]+ echo Hello

=== /QUOTE ===

I'm not sure which behaviour makes more sense here.  It
depends on how you look at it, I guess.

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29,
85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606, 
Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister:
Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb,
Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd


"If you aim the gun at your foot and pull the trigger,
it's
UNIX's job to ensure reliable delivery of the bullet to
where you aimed the gun (in this case, Mr. Foot)."
        -- Terry Lambert, FreeBSD-hackers mailing list.
_______________________________________________
freebsd-standardsfreebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-sta
ndards
To unsubscribe, send any mail to
"freebsd-standards-unsubscribefreebsd.org"

Re: $LINENO within functions
user name
2008-05-30 13:12:42
On Fri, May 30, 2008 at 07:27:12PM +0200, Stefan Farfeleder
wrote:
> Hi,
> 
> SUSv3 says the following about $LINENO:
> 
> "Set by the shell to a decimal number representing
the current
> sequential line number (numbered starting with 1)
within a script or
> function before it executes each command. If the user
unsets or resets
> LINENO , the variable may lose its special meaning for
the life of the
> shell. If the shell is not currently executing a script
or function, the
> value of LINENO is unspecified. This volume of IEEE Std
1003.1-2001
> specifies the effects of the variable only for systems
supporting the
> User Portability Utilities option."
> 
> My initial interpretation of "or function"
was that it means $LINENO
> within a function should be relative to the function's
beginning line.
> Now I'm not so sure anymore.  Bash release 2.05b
changed the expansion
> of $LINENO within functions to absolute numbering,
stating this is
> required by POSIX.  But then I wonder about the meaning
of "or
> function".  Does it mean functions in interactive
scripts?  Because for
> functions in shell scripts the mentioning of both
"script" and
> "function" seems redundant.

I do not know whether you need this data, but ksh93 and
pdksh exhibit
the same behaviour as bash. For the rev. 1.1 of lineno.0, I
got

2
3
6
7
12
13
foo
foo
2

On the other hand, zsh produces

2
3
1
2
12
13
foo
foo
2
Re: $LINENO within functions
user name
2008-05-30 13:15:29
On Fri, May 30, 2008 at 09:12:42PM +0300, Kostik Belousov
wrote:
> On Fri, May 30, 2008 at 07:27:12PM +0200, Stefan
Farfeleder wrote:
> > Hi,
> > 
> > SUSv3 says the following about $LINENO:
> > 
> > "Set by the shell to a decimal number
representing the current
> > sequential line number (numbered starting with 1)
within a script or
> > function before it executes each command. If the
user unsets or resets
> > LINENO , the variable may lose its special meaning
for the life of the
> > shell. If the shell is not currently executing a
script or function, the
> > value of LINENO is unspecified. This volume of
IEEE Std 1003.1-2001
> > specifies the effects of the variable only for
systems supporting the
> > User Portability Utilities option."
> > 
> > My initial interpretation of "or
function" was that it means $LINENO
> > within a function should be relative to the
function's beginning line.
> > Now I'm not so sure anymore.  Bash release 2.05b
changed the expansion
> > of $LINENO within functions to absolute numbering,
stating this is
> > required by POSIX.  But then I wonder about the
meaning of "or
> > function".  Does it mean functions in
interactive scripts?  Because for
> > functions in shell scripts the mentioning of both
"script" and
> > "function" seems redundant.
> 
> I do not know whether you need this data, but ksh93 and
pdksh exhibit
> the same behaviour as bash. For the rev. 1.1 of
lineno.0, I got
> 
> 2
> 3
> 6
> 7
> 12
> 13
> foo
> foo
> 2
> 
> On the other hand, zsh produces
> 
> 2
> 3
> 1
> 2
> 12
> 13
> foo
> foo
> 2

Oh, and /usr/xpg4/bin/sh on the fully patches Solaris 10
output is identical
with the zsh one.
Re: $LINENO within functions
user name
2008-05-30 14:29:29
On Fri, May 30, 2008 at 09:15:29PM +0300, Kostik Belousov
wrote:
> On Fri, May 30, 2008 at 09:12:42PM +0300, Kostik
Belousov wrote:
> > On Fri, May 30, 2008 at 07:27:12PM +0200, Stefan
Farfeleder wrote:
> > > Hi,
> > > 
> > > SUSv3 says the following about $LINENO:
> > > 
> > > "Set by the shell to a decimal number
representing the current
> > > sequential line number (numbered starting
with 1) within a script or
> > > function before it executes each command. If
the user unsets or resets
> > > LINENO , the variable may lose its special
meaning for the life of the
> > > shell. If the shell is not currently
executing a script or function, the
> > > value of LINENO is unspecified. This volume
of IEEE Std 1003.1-2001
> > > specifies the effects of the variable only
for systems supporting the
> > > User Portability Utilities option."
> > > 
> > > My initial interpretation of "or
function" was that it means $LINENO
> > > within a function should be relative to the
function's beginning line.
> > > Now I'm not so sure anymore.  Bash release
2.05b changed the expansion
> > > of $LINENO within functions to absolute
numbering, stating this is
> > > required by POSIX.  But then I wonder about
the meaning of "or
> > > function".  Does it mean functions in
interactive scripts?  Because for
> > > functions in shell scripts the mentioning of
both "script" and
> > > "function" seems redundant.
> > 
> > I do not know whether you need this data, but
ksh93 and pdksh exhibit
> > the same behaviour as bash. For the rev. 1.1 of
lineno.0, I got
> > 
> > 2
> > 3
> > 6
> > 7
> > 12
> > 13
> > foo
> > foo
> > 2
> > 
> > On the other hand, zsh produces
> > 
> > 2
> > 3
> > 1
> > 2
> > 12
> > 13
> > foo
> > foo
> > 2
> 
> Oh, and /usr/xpg4/bin/sh on the fully patches Solaris
10 output is identical
> with the zsh one.

Yes, the current implementation has a +1 offset compared to
zsh.  The
reason is that $LINENO can occur on the same line as the
function name
itself (ie. zsh prints 0 for 'f() { echo $LINENO }' which
contradicts
the specification).
_______________________________________________
freebsd-standardsfreebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-sta
ndards
To unsubscribe, send any mail to
"freebsd-standards-unsubscribefreebsd.org"

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )