Shell 文件包含

Shell 文件包含

Shell 文件包含的语法格式如下:

. filename   # 注意点号(.)和文件名中间有一空格

source filename


实例

创建两个 shell 脚本文件。

test1.sh 代码如下:

#!/bin/bash
url="http://www.runoob.com"


test2.sh 代码如下:

#!/bin/bash
#使用 . 号来引用test1.sh 文件
. ./test1.sh
# 或者使用以下包含文件代码
# source ./test1.sh
echo "地址:$url"

接下来,我们为 test2.sh 添加可执行权限并执行:

$ chmod +x test2.sh 
$ ./test2.sh 
地址:http://www.runoob.com

原文地址:https://www.cnblogs.com/sea-stream/p/9881760.html