Sunday 15 April 2012

error handling - shell ksh function parameter contains another function name to call -


I am trying to write a generic function (such as holder ) - which will take the first parameter The name calls another function name (such as f1, f2, f3, f4 ... ) and based on certain condition.


  #! / Bin / ksh function f1 {echo "F1" return 7} function F2 {echo "F2" return 8} function holder {1 `fptr = $ $ {like fptr}} = rate $? Retractor $ ret. Holder "f1" holder "f2"   

Now the sample works however, sometimes the evaluation line $ {fptr} Strange failures occur with the details of the stack. I suspect that the way I am calling a function can be some problems. A sample is duplicate code above the code, the actual code contains complex f1, f2 logic.

  1. Is it possible to handle such indirect invitations?
  2. Is "calling function" correct in the holder class? Or should it be handled in a different way?

    After the

    It is hard to figure out what causes sporadic failure in your case However, There are some things you want to change:

    1. You probably want to use eval instead of backlit.
    2. You can execute the modified code for the name of the function by using $ 0

      :

       < Code> function F1 {echo $ 0 return 7} function F2 {echo $ 0 return 8} function holder {eval "$ 1" resonance $? } Holder "F1" holder "F2"   

      returns:

        f1 7 f2 8    

No comments:

Post a Comment