加载其他文件变量格式:
. filename # .和文件名之间用空格隔开
source filename
python@ubuntu:~/shellscrip$ vim test1.sh
1 #!/bin/bash
2 array=(1 a b 3)
python@ubuntu:~/shellscrip$ vim test2.sh
1 #!/bin/bash
2 #source /home/python/shellscrip/test1.sh
3 . /home/python/shellscrip/test1.sh
4
5 for i in ${array[@]};do
6 echo $i
7 done
执行结果:
python@ubuntu:~/shellscrip$ chmod +x test1.sh test2.sh
python@ubuntu:~/shellscrip$ ./test2.sh
1
a
b
3