shell 调用其他文件定义的函数

﹥>﹥吖頭↗ 提交于 2019-11-29 21:52:29

用到的命令为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中调用函数

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!