[sh] How can function find invoking line # ?





I would like to write a "die" function (as part of a /bin/sh script)
that starts out by printing out the line from which it was called
(and after doing some cleanup, exits with 1). The intended usage
is like this:

foo bar baz || die "foo failed"

It would be OK if the line number were an argument to the function:

foo bar baz || die 42 "foo failed"

....but hard-coding the line numbers makes editing the script very
tedious.

Is there some special shell variable corresponding to the number
of the line that is currently executing?

Alternatively, is there any way for the die function to determine
the line it was called from?

Thanks!

kj

.