Latest web development tutorials

file di Shell contiene

E altre lingue, Shell possono anche contenere script esterno. In questo modo è facile confezionare un codice comune come un file separato.

file di sintassi Shell contiene quanto segue:

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

或

source filename

Esempi

Creare due file di script di shell.

codice test1.sh è il seguente:

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

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

codice test2.sh è il seguente:

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

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

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

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

Poi, aggiungiamo a test2.sh autorizzazioni di esecuzione e di eseguire:

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

Nota: Il file non ha bisogno di essere inclusi test1.sh permessi eseguibili.