方法一: 使用全局變量
- g_result=""
- function testFunc()
- {
- g_result='local value'
- }
- testFunc
- echo $g_result
方法二: 把shell函數作爲子程序調用,將其結果寫到子程序的標準輸出
- function testFunc()
- {
- local_result='local value'
- echo $local_result
- }
- result=$(testFunc)
- echo $result
{
sum=$(($1+$2))
return $sum
}
add 1 2
echo $?