Re: bash variable expansion moment

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



Joshua,

Thanks for the reply.  But while what you offer would indeed work, but
it's not what I was looking for.

I simplified my example for clarity, was looking to put other text and
variables in Line(), this in order to greatly simplify the code which
calls it.

To rephrase what I'm trying to do:

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.

As said, I'm not sure this can be done at all.  My only grounds for hope
is that bash already does so much so well... I'm constantly amazed at
what can be done with it.  So maybe this is too.

Thanks again for the response.



On 11/15/2009 06:36 AM Joshua Gimer wrote:
> You could pass the value of $LINENO to Line() as a function argument:
> 
> Here's the one file (func-file):
> -------------------------
> Line()
> {
> echo This is line $@
> }
> -------------------------
> 
> That one is called by this one:
> -------------------------
> #!/bin/bash
> 
> . ./func-file
> 
> Line $LINENO
> ------------------------
> 
> Macintosh-5:/tmp joshuagimer$ cat func-file
> Line()
> {
> echo This is line $@
> }
> Macintosh-5:/tmp joshuagimer$ cat test.sh
> #!/bin/bash
> 
> . ./func-file
> 
> Line $LINENO
> Macintosh-5:/tmp joshuagimer$ bash test.sh
> This is line 5
> 
> Thanks
> Josh
> 
> On Sat, Nov 14, 2009 at 5:37 PM, ken <gebser@xxxxxxxxxxxx
> <mailto:gebser@xxxxxxxxxxxx>> wrote:
> 
>     It's half a nice Saturday later and many attempts have brought no
>     satisfaction.  Maybe this can't be done.
> 
>     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):
>     -------------------------
>     Line()
>     {
>     echo This is line "$LINENO" $@
>     }
>     -------------------------
> 
>     That one is called by this one:
>     -------------------------
>     #!/bin/bash
> 
>     . ./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.
> 
>     Any mavens got the skinny on this?
> 
>     tia
> 
> 
>     --
>     War is a failure of the imagination.
>            --William Blake
> 
>     _______________________________________________
>     CentOS mailing list
>     CentOS@xxxxxxxxxx <mailto:CentOS@xxxxxxxxxx>
>     http://lists.centos.org/mailman/listinfo/centos
> 
> 
> 
> 
> -- 
> Thx
> Joshua Gimer
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> CentOS mailing list
> CentOS@xxxxxxxxxx
> http://lists.centos.org/mailman/listinfo/centos
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux