有时候我们想在自己的脚本中引用其他脚本
主脚本
[root@localhost ~]# vim master.sh
#!/bin/bash
#Example script to show how sourcing works
. /root/sourceme
echo the value of variable '$COLOR' is $COLOR
exit 0
被引用的脚本 /root/sourceme
[root@localhost ~]# vim /root/sourceme
COLOR=yellow
执行一下
[root@localhost ~]# chmod +x /root/master.sh
[root@localhost ~]# ./master.sh
the value of variable $COLOR is yellow
[root@localhost ~]#
需要注意的两点:
- 被引用的脚本中不能有exit
- ‘ COLOR′is COLOR,我们如果想把 打印出来,而不被解析成变量的的话,可以用单引号把 包括上。