shell脚本中调用其他脚本的三种方法

方法一:使用 .     #. ./sub.sh

方法二:使用 source    #source ./sub.sh

方法三:使用 sh    #sh ./sub.sh

注意:

1、两个点之间,要有空格,第二个点表示当前目录下

2、如果被调用脚本不在同一个目录下,应该使用绝对路径

3、脚本可带参数

first.sh

#!/bin/bash
echo 'your are in first file'
echo "${0} ${1}"

second.sh

#!/bin/bash
echo 'your are in second file'
echo "${0} ${1}"

. ./first.sh ${2} 

执行:./second.sh abc 123

your are in second file
./second.sh abc
your are in first file
./second.sh 123

原文地址:https://www.cnblogs.com/mgzc-1508873480/p/7866768.html