[CentOS] bash variable expansion moment

ken gebser at mousecar.com
Sun Nov 15 18:50:30 UTC 2009

On 11/15/2009 08:54 AM Stephen Harris wrote:
> On Sun, Nov 15, 2009 at 08:23:59AM -0500, ken wrote:
>> A function containing environmental variables in one file would be
>> called in another file.  The function would, then, pass (e.g.) $LINENO
>> as if it were a literal, but in the line where $Line is invoked it would
>> be evaluated and the value output.
> I'm not quite sure what you're saying.  Typically variables are not expanded
> at 'parse' time, but at run time.
> ....

>From the original post (somewhere got edited out):

I'm trying to write a function which, when called from one function
execute in another.  In itself, that's not the problem.  Rather, there's
one built-in variable which is evaluated in the function definition and
it's value is then set (too early).

Here's the one file (func-file):
echo This is line "$LINENO" $@

That one is called by this one:

. ./func-file

Line ... it should be $LINENO

I want the function Line to show the line number in the second file
where it's executed, not the line number from the sourced function.


The problem is that $LINENO is evaluated in the function definition, and
not when called.  So I'm thinking to change "$LINENO" in the function
definition to some other syntax so that it won't be evaluated until called.


More information about the CentOS mailing list