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

前端 未结 9 1420
再見小時候
再見小時候 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:20

    Briefly, no.

    You can import all of the functions in the script into your environment with source (help source for details), which will then allow you to call them. This also has the effect of executing the script, so take care.

    There is no way to call a function from a shell script as if it were a shared library.

提交回复
热议问题