shell在執行的時候是順序執行的,也不存在什么多線程什么的。
一下是實現種類:
1、全局
g_result="" function testFunc() { g_result='local value' } testFunc echo $g_result
2、局部
function testFunc() { local_result='local value' echo $local_result } result=$(testFunc) echo $result
3、return返回特殊用法
function test() { return 1 } echo $?
可以看出$?是用來接收的
參考:
https://www.linuxjournal.com/content/return-values-bash-functions
http://www.blogjava.net/xzclog/archive/2015/09/21/427407.html
https://blog.csdn.net/mdx20072419/article/details/9381339