有没有办法在 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/