方法一: 使用全局變量
- g_result=""
-
- function testFunc()
- {
- g_result='local value'
- }
-
- testFunc
- echo $g_result
方法二: 把shell函數(shù)作為子程序調(diào)用,將其結(jié)果寫到子程序的標(biāo)準(zhǔn)輸出- function testFunc()
- {
- local_result='local value'
- echo $local_result
- }
-
- result=$(testFunc)
- echo $result
看到一篇關(guān)于函數(shù)返回值的好文章,分享一下: http://www.linuxjournal.com/content/return-values-bash-functions
posted on 2015-09-21 10:20
xzc 閱讀(4442)
評論(2) 編輯 收藏 所屬分類:
linux/unix