Anonymous functions in shell scripts

前端 未结 6 1763
無奈伤痛
無奈伤痛 2021-01-03 20:00

Is it possible to create something analogous to an anonymous function whose value can be assigned to an array element and later called? I can\'t seem to find a way to do thi

6条回答
  •  甜味超标
    2021-01-03 20:57

    If you really need array to store the functions, you can define named functions and store just their names. You can then call the function as ${array[n]}. Or, you can name them func1 .. funcN and then just call func$n.

提交回复
热议问题