用到的命令为source,我也是在teamviewer里的脚本中看到的。比较相似于python中import modulepython
[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中调用函数shell