Ian Shields Ph.D.
Linux Technologist, ISV & Developer Relations
IBM Corp
Research Triangle Park, NC
[EMAIL PROTECTED]
[EMAIL PROTECTED] wrote on 09/16/2008 07:17:53 AM:
> 2008/9/16 Peter Kruse <[EMAIL PROTECTED]>:
> > Hello,
> >
> > Ian Shields wrote:
> >>
> >> I guess the most important thing is that Bash doesn't support
function
> >> nesting. Try entering the whole thing in Bash and the run f1. Also
try
> >> recalling the function and press enter.
> >
> > Have you tried that yourself? I did that and this is what happens:
> >
> > ---------------------8<--------------------------------------
> > $ echo $BASH_VERSION
> > 3.1.17(1)-release
> > $ f1() { f2() { echo "Function "f2", inside "f1"."; }; }
> > $ f2
> > bash: f2: command not found
> > $ f1
> > $ f2
> > Function f2, inside f1.
> > $ _
> > ---------------------8<--------------------------------------
> >
> > that means you can define a function inside of a function and make
that
> > nested function globally available. In other words a function
> > can define a function. I only wanted to point out that the
> > quoting in f2() is rather useless, it should probably look like:
> >
> > echo "Function 'f2', inside 'f1'."
> >
> > Regards,
> >
> > Peter
> >
> >
>
> Thanks for the answer, incidentally I've found googling bash function
nested:
>
> http://tldp.org/LDP/abs/html/functions.html
Thanks to both of you for enlightening me. I did not know that function
nesting was possible in Bash. As the TLDP article points out though, it's
not very useful as you have to run f1 to make f2 visible and f2 is then
globally visible, so what has been gained? And yes, I did try running f1,
but not f2. I also tried using the up arrow to recall the function
definition which usually recalls a single line like (although it may be
broken when posted):
f1 () { f2 () # nested { echo "Function \"f2\", inside \"f1\"."; }; }
This puts up a > prompt, indicating that more input is expected. Of
course, that's because the # now comments all the remaining input.
_______________________________________________
lpi-discuss mailing list
[email protected]
http://list.lpi.org/cgi-bin/mailman/listinfo/lpi-discuss