It is currently Tue, 30 Nov 2021 18:31:39 GMT



 
Author Message
 bash: function-defining function?

This is an admittedly perverse question: in bash, can one define
a function that in turn defines another function?  E.g.:

$ cat naive
function alias () {
  name=$1;
  shift;
  function $name () { "$@" }
$ . naive
bash: ./naive: line 6: syntax error: unexpected end of file

More perversely still, if it is possible to do it at all, is it
possible to do it from the bash command line?

TIA,

        -Irv



 Sat, 07 Jan 2006 22:57:07 GMT   
 bash: function-defining function?
In article <bfjjc3$gj...@reader1.panix.com>,
Irving Kimura  <irving_kim...@lycos.com> wrote:

You can do it with eval:

function myalias () {
  name=$1
  shift
  eval "function $name () { " "$@" " }"

--
Barry Margolin, barry.margo...@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



 Sat, 07 Jan 2006 23:06:37 GMT   
 
   [ 2 post ] 

Similar Threads

1. function, function...who's got the function?

2. GNU bash shell -- how to do csh alias things in bash functions

3. testing whether a function is defined

4. is __FUNCTION__ a pre-defined macro in CC?

5. problems with errno defined as function

6. Defining FN keys to WM functions

7. virtual function define problem

8. Sun WorkShop 5.0: multiply defined inline functions

9. Function illegally defined in hosted mode

10. how to define etermx function key with modifier?


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software