1. 程式人生 > >Shell 文件包含

Shell 文件包含

代碼 bash chm pla print isp pan 可執行 註意

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

Shell 文件包含