How to tell if the output of the "find" command is empty?

Answer #1 96.1 %

When you say you want it to return a particular number, are you referring to the exit status? If so:

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

And since you only care about a yes/no response, you may want to change your find to this:

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

which will stop after the first core file found. Without that, if the root directory is large, the find could take a while.

Answer #2 85.7 %

Here's my version. :)

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

Edited for brevity:

[ -z "$(find /this/is/a/path/ -name 'core.*')" ]
Tags: bashpipe

You’ll also like:

© 2022 CodeForDev.com -