我想在shell中運行某些操作,具體取決於當前目錄中的默認生成文件是否包含特定目標。如何在生成文件中檢查目標的存在
#!/bin/sh
make -q some_target
if test $? -le 1 ; then
true # do something
else
false # do something else
fi
這是有效的,因爲如果目標不存在,GNU make返回錯誤代碼2,否則返回0或1。問題是沒有以這種方式記錄。這裏是男人的一部分:
-q, --question
``Question mode''. Do not run any commands, or print anything;
just return an exit status that is zero if the specified targets
are already up to date, nonzero otherwise.
只有零/非零區分。什麼是正確的方法來做到這一點?
所以沒有辦法從其它任何區分這種錯誤,而是通過解析stderr輸出? – sshilovsky
正確; make不會爲可能遇到錯誤的每種可能方式使用不同的錯誤代碼。 – MadScientist