請問envsetup.sh里邊,function gettop() {local TOPFILE=build/core/envsetup.mkif [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; thenecho $TOPelseif [ -f $TOPFILE ] ; then# The following circumlocution (repeated below as well) ensures# that we record the true directory name and not one that is# faked up with symlink names.PWD= /bin/pwdfi}并沒有返回值。
1 回答

萬千封印
TA貢獻1891條經驗 獲得超3個贊
shell中的函數,跟c的不一樣。c想要返回值,要么使用全局變量,要么使用return,要么使用指針。
而shell中的函數,你要得到shell函數處理后的值。要么把處理的結果寫到文件中,或者輸出。
我這里舉例輸出,不過這樣不太方便
[root@localhost Desktop]# cat test.sh
#!/bin/bash
print()
{
echo "hello world"
echo "world hello"
}
a=`print`
echo ${a}
[root@localhost Desktop]# sh test.sh
hello world world hello
[root@localhost Desktop]#
shell中函數調用時,有輸出。函數調用有返回值,一般使用return來指定。如果不指定,默認為函數中最后一個語句的返回值。
- 1 回答
- 0 關注
- 249 瀏覽
添加回答
舉報
0/150
提交
取消