Re: 回复: Bug in dash: Incorrect behaviour of $LINENO in function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jan 14, 2023 at 11:10:45AM +0000, Harald van Dijk wrote:
> On 14/01/2023 10:57, anonymous4feedback@xxxxxxxxxxx wrote:
> > Sorry I didn't explain this clearly, and I made some wrong assumption in the first email.

don't be: maybe at just misread you :)

> > dash prints 2, (line number in function, counting from 1)
> > bash and ksh prints 4, (line number in whole script)
> > and zsh prints 1 (line number in function, counting from 0)

to me, $LINENO should be read as "number of lines from $0" so you can
write 

	echo error at $0 line $LINE

none of them break this rule AFAIK:

	<<\% cat -- > /tmp/pa
	S=$1
	f() {
		echo $S: . $LINENO
	}
	f
	%
	<<% xargs -IS sh -c 'S /tmp/a S'
	zsh
	yash
	bash
	mksh
	$HOME/src/vendor/dash/src/dash

gives

	zsh: e . 1
	yash: /tmp/a . 3
	bash: /tmp/a . 3
	mksh: /tmp/a . 3
	/home/mc/src/vendor/dash/src/dash: /tmp/a . 2

to me, is the only one problematic here (there is no line 0)

> There is a standard about this, but it, in my opinion, is unclear what the
> correct behaviour is.

as I find the opengroup site (intentionaly?) hard to read, there is the link:

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html

> There are a few more cases with LINENO that prove problematic, see also my
> response to an earlier bug report at
> <https://marc.info/?l=dash&m=153725795810101>.

Sometimes, function overwrite and aliases leads to really simple
and powerful script designs. So after 25 years of shell scripting,
what I think should be standard is:

	when inside a function, $0 and $LINENO correspond to
	the filename and line number in that file starting from 1
	and without any alias expansion.

But I like your conclusion too:

	"As for the rest, unless there are strong reasons to go after a
	particular result, since POSIX says the results are unspecified,
	I would suggest going with whatever is the simplest to implement."

regards
marc



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux