如何在命令行中从脚本运行功能? [英] How can I run a function from a script in command line?

查看:63
本文介绍了如何在命令行中从脚本运行功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有某些功能的脚本.

I have a script that has some functions.

我可以直接从命令行运行功能之一吗?

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

像这样吗?

myScript.sh func()

推荐答案

如果脚本仅定义函数且不执行其他任何操作,则可以首先使用source命令,然后只需调用该函数.有关更多信息,请参见help source.

If the script only defines the functions and does nothing else, you can first execute the script within the context of the current shell using the source or . command and then simply call the function. See help source for more information.

这篇关于如何在命令行中从脚本运行功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆