Bourne Shell:获得退出状态的优雅方式

six*_*ude 2 unix bash scripting sh exitstatus

有没有更优雅的方式来做这个(bourne shell)?

IsThereAnyApplesLeft
applesLeft=$?
Run Code Online (Sandbox Code Playgroud)

通常在c或java中我会这样做:

applesLeft=IsThereAnyApplesLeft
Run Code Online (Sandbox Code Playgroud)

Jür*_*zel 6

退出状态通常隐式使用,如下所示:

if IsThereAnyApplesLeft;then
   echo "Apples left"
fi
Run Code Online (Sandbox Code Playgroud)