Latest web development tutorials

Shell file contains

And other languages, Shell may also contain external script. This makes it easy to package some common code as a separate file.

Shell syntax file contains the following:

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

或

source filename

Examples

Create two shell script files.

test1.sh code is as follows:

#!/bin/bash
# author:本教程
# url:www.w3big.com

url="http://www.w3big.com"

test2.sh code is as follows:

#!/bin/bash
# author:本教程
# url:www.w3big.com

#使用 . 号来引用test1.sh 文件
. ./test1.sh

# 或者使用以下包含文件代码
# source ./test1.sh

echo "本教程官网地址:$url"

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

$ chmod +x test2.sh 
$ ./test2.sh 
本教程官网地址:http://www.w3big.com

Note: The file does not need to be included test1.sh executable permissions.