如何在bash shell脚本中包含文件 [英] How to include file in a bash shell script

查看:276
本文介绍了如何在bash shell脚本中包含文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以在外壳程序脚本中包含另一个外壳程序脚本,以便能够访问其功能?

Is there a way to include another shell script in a shell script to be able to access its functions?

就像在PHP中可以如何将include指令与其他PHP文件一起使用,以便仅通过调用函数名来运行包含在其中的函数.

Like how in PHP you can use the include directive with other PHP files in order to run the functions that are contained within simply by calling the function name.

推荐答案

只需将其放入脚本中即可:

Simply put inside your script :

source FILE

. FILE

是同一回事.

$ LANG=C help source
source: source filename [arguments]
Execute commands from a file in the current shell.

Read and execute commands from FILENAME in the current shell.  The
entries in $PATH are used to find the directory containing FILENAME.
If any ARGUMENTS are supplied, they become the positional parameters
when FILENAME is executed.

Exit Status:
Returns the status of the last command executed in FILENAME; fails if
FILENAME cannot be read.

这篇关于如何在bash shell脚本中包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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