Latest web development tutorials

fichier Shell contient

Et d'autres langues, Shell peuvent également contenir script externe. Cela rend plus facile d'emballer un peu de code commun dans un fichier séparé.

fichier de syntaxe Shell contient les éléments suivants:

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

或

source filename

Exemples

Créez deux fichiers de script shell.

test1.sh code est le suivant:

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

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

test2.sh code est le suivant:

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

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

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

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

Ensuite, nous ajoutons à test2.sh autorisations exécutables et effectuer:

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

Remarque: Le fichier n'a pas besoin d'être inclus test1.sh autorisations exécutables.