Test whether a glob has any matches in bash

后端 未结 19 2381
夕颜
夕颜 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:49

    If you have globfail set you can use this crazy (which you really should not)

    shopt -s failglob # exit if * does not match 
    ( : * ) && echo 0 || echo 1
    

    or

    q=( * ) && echo 0 || echo 1
    

提交回复
热议问题