Borrowing code from 4ae1e1 comment:
Find the first exception to the rule (if any) in each subdirectory specified on the command line. Print it, if allowed.
dir_filesize_rangefilter() { # args: lo hi paths... # sizes in MiB # return value: dir names printed to stdout local lo=$1 hi=$2 shift 2 # " $@ " is now just the paths for dir; do # in " $@ " is implicit local safedir=$dir [[ $dir = /* ]] || safedir=./$dir # make sure find doesn't treat weird -filenames as -options # find the first file smaller than lo or larger than hi [[ -z "$(find "$safedir" -type f \( -size "-${lo}M" -o -size "+${hi}M" \) -print -quit )" ]] && printf '%s\n' "$dir" done }
I used "printf" because "echo" breaks if one of the directory names starts with -e or something like that. You may have added the allowed directories to the array instead of printing them to stdout if you really want to be paranoid with respect to the actual file names (since you have to parse the output of this using the while IFS= read or something that allows any character, and which still breaks dir names containing a new line.)
Apparently, SO syntax highlighting doesn't know citation rules inside $(command substitution) : /
source share