shell 脚本退出码 lushuan 收录于 Shell 2020-04-18 约 126 字 预计阅读 1 分钟 目录 很多时候我们需要获取脚本的执行结果,即退出状态,通常0表示执行成功,而非0表示失败。为了获得退出码,我们需要使用exit 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #!/bin/bash function myfun() { if [ $# -lt 2 ] then echo "para num error" exit 1 fi echo "ok" exit 2 } if [ $# -lt 1 ] then echo "para num error" exit 1 fi returnVal=`myfun aa` echo "end shell" exit 0 Please enable JavaScript to view the comments powered by Gitalk. Please enable JavaScript to view the comments powered by Giscus.