shell 调用其他shell脚本中的变量、函数

时间:2024-04-30 23:38:22

在Shell中要如何调用别的shell脚本,或别的脚本中的变量,函数呢?

方法一:   . ./subscript.sh  (两个点之间,有空格)

方法二:   source ./subscript.sh

以第一种方式为例:

sub.sh

shell  调用其他shell脚本中的变量、函数

main.sh

shell  调用其他shell脚本中的变量、函数

执行输出:

shell  调用其他shell脚本中的变量、函数

 注意:

1.在main.sh中调用sub.sh脚本后,sub.sh中的命令都会执行

2.在main.sh中调用sub.sh脚本中注意脚本路径,可以为相对路径,也可为绝对路径