Test whether a glob has any matches in bash

后端 未结 19 2374
夕颜
夕颜 2020-11-22 15:51

If I want to check for the existence of a single file, I can test for it using test -e filename or [ -e filename ].

Supposing I have a glob

相关标签:
19条回答
  • 2020-11-22 16:58

    Based on flabdablet's answer, for me it looks like easiest (not necessarily fastest) is just to use find itself, while leaving glob expansion on shell, like:

    find /some/{p,long-p}ath/with/*globs* -quit &> /dev/null && echo "MATCH"
    

    Or in if like:

    if find $yourGlob -quit &> /dev/null; then
        echo "MATCH"
    else
        echo "NOT-FOUND"
    fi
    
    0 讨论(0)
提交回复
热议问题