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

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

问题描述

我有一个包含一些功能的脚本.

我可以直接从命令行运行其中一个函数吗?

类似的东西?

myScript.sh func()

解决方案

如果脚本只定义了函数而没有做其他事情,您可以先使用 sourcesource

在当前 shell 的上下文中执行脚本code> 或 . 命令,然后简单地调用该函数.有关详细信息,请参阅 帮助源.

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()

解决方案

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天全站免登陆