Shell globbing patterns potentially expand to more than one pathname. For example, if /a/*/b/file.asd
expands to multiple pathnames, then the test that you are performing becomes nonsensical.
Also, shell globs are not expanded inside [[ ... ]]
. From the bash
manual:
Word splitting and pathname expansion are not performed on the
words between the [[
and ]]
If you know that you want to perform the test on a particular file, e.g. /a/x/b/file.asd
, then use that pathname in the test. If you want to perform the test on all pathnames that matches that pattern, use a loop:
shopt -s nullglob dotglob
for pathname in /a/*/b/file.asd; do
if [[ $pathname -nt /c/d/file.asd ]]; then
printf 'found new file: %s\n' "$pathname"
fi
done
The nullglob
and dotglob
shell options are set so that the pattern is removed if it does not match anything and so that *
catches any hidden directories.
Also, the test could be done with find
, unless the pattern /a/*/b/file.asd
expands to many thousands of pathnames:
find /a/*/b/file.asd -prune -type f -newer /c/d/file.asd
This would expand the pattern /a/*/b/file.asd
and use each of the pathnames that it expands to as a search path for find
. The search paths are tested against /c/d/file.asd
and the pathnames are printed if they are newer than that file. The -prune
stops find
from moving down into a search path, just in case any of them refers to a directory.