shell中通过字符串执行函数

2019-08-06  本文已影响0人  崔天浩

需求描述:

  1. shell脚本中定义了很多功能函数,我要通过执行脚本传入参数执行函数,参数为函数名字,
#!/bin/bash

function test(){
        echo "my is test function"
}

module=$1

解决方法

#!/bin/bash

function test(){
        echo "my is test function"
}

module=$1
eval ${module}

执行结果

sh function.sh  test
my is test function
上一篇 下一篇

猜你喜欢

热点阅读