find is not great for such tests
it will exit 0 if it finds a file or not
it will only exit non-zero if something went "wrong" ( like incorrect arguments )
I'm not 100% certain I have the logic right
both have to find things to not run the command
Code:
#!/bin/bash
error_in_find () {
echo "something went very wrong with find" 1>&2
exit 1
}
_find1 () {
find /path/to/folder1 \
-type f \
! -path "*configs*" \
-size -800k \
-printf "[[Warning]]: %f size is under 800 Kilobytes\n" \
|| error_in_find
}
_find2 () {
find /path/to/another/folder \
-type f \
\( ! -iname "123.file*" \) \
! -path "*logs*" \
-size -40k \
-printf "[[Warning]]: %f size is under 40 Kilobytes\n" \
|| error_in_find
}
dontrun=y
grep --colour=no "." < <(_find1) || unset dontrun
grep --colour=no "." < <(_find2) || unset dontrun
[[ $dontrun ]] || run_your_command
#
testing to exit code of grep, "." is any char. so if the finds printed anything grep returns 0
if the finds don't print anything, grep returns 1
when grep finds something, we unset the dontrun var
when grep does not find something, we unset the dontrun var
so, both have to print ( find ) something to not run
if any of them fail to print ( find ) something the run_your_command is run.