Latest web development tutorials

archivo contiene Shell

Y otros idiomas, Shell también pueden contener script externo. Esto hace que sea fácil de empaquetar un código común como un archivo separado.

archivo de sintaxis Shell contiene lo siguiente:

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

或

source filename

Ejemplos

Crear dos archivos de comandos shell.

código test1.sh es el siguiente:

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

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

código test2.sh es el siguiente:

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

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

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

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

A continuación, añadimos a test2.sh permisos de ejecución y llevar a cabo:

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

Nota: El archivo no necesita ser incluido test1.sh permisos de ejecución.