2011-06-29 39 views

回答

14

當你說你希望它返回一個特定的號碼,你指的是退出狀態?如果是這樣的:

[[ -z `find /this/is/a/path/ -name core.*` ]] 

而且因爲你只關心是/否響應,您可能需要您發現改成這樣:

[[ -z `find /this/is/a/path/ -name core.* -print -quit` ]] 

找到的第一個核心文件之後,將停止。沒有這一點,如果根目錄很大,查找可能需要一段時間。

+0

如果輸出爲非空,則返回0,而不是空。 –

+1

糟糕。邏輯被扭轉了。以上更正。 Alex對'-qu''選項用'-z' –

+2

+1正確,非常好! – 2011-06-29 21:58:56

3

可能有許多變種,但是這是一個:

test $(find /this/is/a/path/ -name core.* | wc -c) -eq 0 
4

這裏是我的版本。 :)

[ -z "$(find /this/is/a/path/ -name 'core.*')" ] && true 

編輯爲簡潔:

[ -z "$(find /this/is/a/path/ -name 'core.*')" ] 
+0

什麼是'&& TRUE'呢? –

+0

嘿,我在想,「設置退出狀態。」但是,是啊,測試已經這樣做了,這完全沒有必要,很好。 –

1

也許這

find /this/is/a/path/ -name 'core.*' | read 
相關問題