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


And there is just the same example, and it says:

It is even possible to nest a function within another function,
although this is not very useful.

f1 ()
{

  f2 () # nested
  {
    echo "Function \"f2\", inside \"f1\"."
  }

}

f2  #  Gives an error message.
    #  Even a preceding "declare -f f2" wouldn't help.

echo

f1  #  Does nothing, since calling "f1" does not automatically call "f2".
f2  #  Now, it's all right to call "f2",
    #+ since its definition has been made visible by calling "f1".


I hope that be useful for someone....
-- 
--
Open Kairos http://www.openkairos.com
Watch More TV http://sebelk.blogspot.com
Sergio Belkin -
_______________________________________________
lpi-discuss mailing list
[email protected]
http://list.lpi.org/cgi-bin/mailman/listinfo/lpi-discuss

Reply via email to