Shell file contains


Like other languages, the Shell can also contain external scripts. This can easily encapsulate some common code as a separate file.

The syntax format contained in the Shell file is as follows:

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

Example

Create two shell script files.

test1.sh code is as follows:

#!/bin/bash # author:php中文网 # url:m.sbmmt.com url="//m.sbmmt.com"

test2.sh code is as follows:

#!/bin/bash # author:php中文网 # url:m.sbmmt.com #使用 . 号来引用test1.sh 文件 . ./test1.sh # 或者使用以下包含文件代码 # source ./test1.sh echo "php中文网官网地址:$url"

Next, we add executable permissions to test2.sh and execute:

$ chmod +x test2.sh $ ./test2.sh php中文网官网地址://m.sbmmt.com

Note:The included file test1.sh does not require executable permissions.