linux - 如何在 bash shell 脚本中包含文件

有没有办法在 shell 脚本中包含另一个 shell 脚本以便能够访问其功能?

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

最佳答案

只需放入您的脚本中:

source FILE

或者

. FILE # POSIX compliant

$ 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.

https://stackoverflow.com/questions/10823635/

相关文章:

python - 如何在 Python Django 中运行单元测试时禁用日志记录?

linux - 如何在 bash 中检查文件是否创建时间超过 x 时间?

linux - 如何在 Bash 中解析 CSV 文件?

python - 如何模拟在 with 语句中使用的 open (使用 Python 中的 Mock

python - 在 Python 中注释函数的正确方法是什么?

c - Linux:是否有超时的套接字读取或接收?

python - 为什么 4*0.1 的浮点值在 Python 3 中看起来不错,但 3*0.1 不

python - 多处理。池 : What's the difference between map

linux - 如何在命令行中合并图像?

linux - 有没有办法改变 Unix 中另一个进程的环境变量?