星期二, 6月 20, 2006

Shell Script : test exit status of command

上次的shell script需要判斷執行程式exit code。-- 結果沒找到。
現在找到了,原來是用 ' $?' 符號。

常用的符號有:
$# 參數的數目
$* 代表所有參數
$? Exit status of previous command
$$ PID of this shell's process
$! PID of the most recently started backgroup job

這樣就可以啦。

使用的時候...
./probe_program   <先執行程式
if test $? = 0;then
echo ok
else
echo fail!
fi
...

沒有留言:

網誌存檔