[CentOS] bash variable expansion moment

Joshua Gimer jgimer at gmail.com
Sun Nov 15 11:36:44 UTC 2009


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 at mousecar.com> 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 at centos.org
> http://lists.centos.org/mailman/listinfo/centos
>



-- 
Thx
Joshua Gimer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.centos.org/pipermail/centos/attachments/20091115/478f5937/attachment.html 


More information about the CentOS mailing list