How can I run a function from a script in command line?

前端 未结 9 1423
再見小時候
再見小時候 2020-12-07 08:05

I have a script that has some functions.

Can I run one of the function directly from command line?

Something like this?

myScript.sh func()
         


        
9条回答
  •  天涯浪人
    2020-12-07 08:43

    you can call function from command line argument like below

    function irfan() {
    echo "Irfan khan"
    date
    hostname
    }
    function config() {
    ifconfig
    echo "hey"
    }
    $1
    

    once you function end put $1 to accept argument let say above code is saved in fun.sh to run function ./fun.sh irfan & ./fun.sh config

提交回复
热议问题