用到的命令为source,我也是在teamviewer里的脚本中看到的。比较类似于python中import module
[root@openstack ~]# cat hello.sh
#!/bin/bash
source /root/h.sh
echo "hello world"
fname
[root@openstack ~]# cat h.sh
#!/bin/bash
fname ()
{
echo "abc"
}
#export -f fname
[root@openstack ~]# bash hello.sh
hello world
abc
另一种方式是 export -f fname 这个是在shell 脚本攻略里看到的。有兴趣的可以尝试一下。在子shell中调用函数
来源:oschina
链接:https://my.oschina.net/u/184200/blog/190957