shell 返回值lushuan 收录于 Shell 2020-04-22 约 122 字 预计阅读 1 分钟 目录 通常函数的return返回值只支持0-255,因此想要获得返回值,可以通过下面的方式。1 2 3 4 5 function myfunc() { local myresult='some value' echo $myresult } val=$(myfunc) #val的值为some value 通过return的方式适用于判断函数的执行是否成功: 1 2 3 4 5 6 7 8 9 10 function myfunc() { #do something return 0 } if myfunc;then echo "success" else echo "failed" fi Please enable JavaScript to view the comments powered by Gitalk.Please enable JavaScript to view the comments powered by Giscus.