可以在bash函数在不同的脚本中使用? [英] Can a bash function be used in different scripts?

查看:103
本文介绍了可以在bash函数在不同的脚本中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了我要引用和不同的脚本使用的功能。有没有办法做到这一点?我不希望被重写为不同的脚本相同的功能。谢谢你。

I've got a function that I want to reference and use across different scripts. Is there any way to do this? I don't want to be re-writing the same function for different scripts. Thanks.

推荐答案

当然 - 在你的脚本,你要使用的功能,你可以这样写

Sure - in your script, where you want to use the function, you can write a command like

source function.sh

这相当于包括 function.sh 在其中该命令运行该点在文件中的内容。需要注意的是 function.sh 需要在一个目录中的 $ PATH ;如果不是的话,你需要指定一个绝对路径。

which is equivalent to including the contents of function.sh in the file at the point where the command is run. Note that function.sh needs to be in one of the directories in $PATH; if it's not, you need to specify an absolute path.

这篇关于可以在bash函数在不同的脚本中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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