[CentOS] bash variable expansion moment

Stephen Harris lists at spuddy.org
Sun Nov 15 23:32:11 UTC 2009

On Sun, Nov 15, 2009 at 06:21:40PM -0500, ken wrote:

> > Is this what you wanted to do?
> Stephen, thanks for your reply, but you're not seeing what I want to do.
>  Let me post my example once again:

You're not reading what I wrote.

> -------------------------
> Line()
> {
> echo This is line "$LINENO" $@

As I said in my previous mail, use ${BASH_LINENO[0]} instead, which tells
you the line it was called from.


  $ cat func-file
    echo This is line "${BASH_LINENO[0]}" $@

  $ cat x

  . ./func-file

  Line ... it should be $LINENO

  $ ./x
  This is line 5 ... it should be 5

> but it's not.  The num output in "This is line [num]" is whatever the
> line number is in the function definition.  (I.e., $LINENO is evaluated
> in the function.  Try it if you don't believe me.)

I explained to you _exactly_ why you are seeing the behaviour you are
seeing.  Your interpretation of what is happening is wrong.  $LINENO
gets _reset_ when you enter a function.

> What I'm looking for is the proper syntax to wrap around $LINENO in the

You can _not_ use $LINENO in this manner.  You _must_ use the BASH_LINENO
array.  That's what it was created for.

> function definition (in func-file) so that it's not evaluated there but
> is evaluated when the function is called in the second file.

You clearly don't understand how scripts are evaluated.  I've given you
the answer; I've proven it with output from the shell; I've referenced
the documentation; I've explained how this works.

I even told you the solution and what variable you should use.

I give up.



More information about the CentOS mailing list