shell 調用其餘文件定義的函數

用到的命令爲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

相關文章
相關標籤/搜索