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

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

 



hello,

> It seems dash stores the line number of the parameter substitution and the line number of the function definition

which is what we expect from a variable expansion. what you need here
is an alias because it works like a minimal but dynamic preprocessor

those are the tricks about aliases:

* they really act as a preprocessor so

	alias warn='>&2 echo here at $LINENO'
	f() warn first
	alias warn='>&2 echo another message at $LINENO'
	g() warn last
	f;g

	# does

	here at 1 first
	another message at 1 last

* interpolation comes first so 

	entering() {
		echo entering "$@"
		"$@"
	}
	f() echo doing things in functions
	alias damn='echo oops ...'
	entering f
	entering damn

	entering f
	doing things in functions
	entering damn
	/home/mc/src/vendor/dash/src/dash: 3: damn: not found

conclusion:

* use functions as long as you can
* in this case, you can't. your solution is

	alias warn='>&2 echo here at $LINENO'

HTH,
Marc Chantreux



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

  Powered by Linux