1
我有我的tcsh啓動腳本如下代碼:在tcsh中,如何獲得反引號中命令的退出狀態?
set _color_count = `sh -c "tput -T${TERM}-256color colors 2>/dev/null"`
if ($? == 0) then # check if it was a valid terminal type
if ($_color_count != 256) then # sanity-check
echo "Warning: Color count '$_color_count' for '${TERM}-256color' is not 256"
endif
setenv TERM "${TERM}-256color"
endif
我的問題是退出狀態($?)是總是爲零,即使tput
命令返回非零退出狀態,由於到無效的終端類型。如果我不捕獲命令的輸出,檢查退出狀態正常工作:
sh -c "tput -T${TERM}-256color colors 2>/dev/null"
如何確定tput
命令是否返回非零退出狀態,因爲它是在反引號?