2013-04-09 26 views
0

如何測試從給定模式命名的文件(或多個)是否存在並根據該測試進行測試?測試bash中是否存在來自給定模式的文件

這是我的失敗嘗試:

[[ { ls ../outputListWorkerPid_* | wc -l } -ge "1" ]] && echo "ARRRRRR" || && echo "FAIL" 

但我得到了以下錯誤:

bash: conditional binary operator expected 
bash: syntax error near `ls' 

而且這將是很好,以避免lsNo such file or directory在不存在的情況下。

+1

這個答案對你有幫助嗎? http://stackoverflow.com/questions/6363441/check-if-a-file-exists-with-wildcard-in-shell-script – AlexLordThorsen 2013-04-09 17:01:50

+0

是的,非常感謝! – RSFalcon7 2013-04-09 17:03:15

回答

-1

使用if語句:

if [ "$(ls *.txt | wc -l)" -ge "1" ]; 
then 
    echo "Yes"; 
else 
    echo "No"; 
fi; 

是否回答你的問題?

相關問題