Given a tree of files like this:
subdirFoo/2019-06-01-blah.ext subdirFoo/2019-06-07-blah.ext subdirFoo/2019-05-02-blah.ext subdirBar/2019-06-03-blah.ext subdirBar/2019-05-05-blah.ext subdirBar/2019-05-13-blah.ext I want to iterate over these files and pass them as arguments to somecommand, BUT, I want to iterate over them in sorted order by the FILENAMES, not the full paths.
Normally, globs are sorted alphabetically, but I get them in this order:
subdirBar/2019-05-05-blah.ext subdirBar/2019-05-13-blah.ext subdirBar/2019-06-03-blah.ext subdirFoo/2019-05-02-blah.ext subdirFoo/2019-06-01-blah.ext subdirFoo/2019-06-07-blah.ext meaning to say, the subdirectories are considered in the sorting, which is not what I want.
How can I get the glob to be sorted by filename only, but still keep the subdir in the loop so that the command can reference the file correctly? i.e. stripping off the subdir won't work because then the path to the file is incorrect/lost.
i.e. I need them in this order:
subdirFoo/2019-05-02-blah.ext subdirBar/2019-05-05-blah.ext subdirBar/2019-05-13-blah.ext subdirFoo/2019-06-01-blah.ext subdirBar/2019-06-03-blah.ext subdirFoo/2019-06-07-blah.ext Solution in zsh preferred, but I can accept bash or sh.