0

If I have any a single xyz.PDF file this works:

[ -e *.PDF* ] && echo 'yes'

However if I have two files, e.g.

xyz.PDF
abc.PDF

I get

$ [ -e *.PDF* ] && echo 'yes'
-bash: [: sometstgg.PDF: binary operator expected

How to get around this and allow for either 1 or many files?

0

1 Answer 1

0
set -- *.PDF

[ "$#" -gt 0 ] && [ "$*" != "*.PDF" ] && echo 'yes'

There probably is a better solution as this would fail if there is something with the actual name *.PDF there.

For bash I think it would be enough with

shopt -s nullglob
set -- *.PDF

[[ "$#" -gt 0 ]] && echo yes

In ksh93, this seems to be enough:

[ -e *.PDF ] && echo yes

Not the answer you're looking for? Browse other questions tagged .