Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Suppressing failed glob patterns



[Sorry -- responded from the wrong address, and didn't get the mailing list notice until today]

On Thu, 4 Dec 2008, Thorsten Kampe wrote:

rm was of course only an example. You can substitute ls or print or whatever to see what I mean.

Thorsten

You might also be interested in the '--no-run-if-empty' flag to 'xargs'.

pros: doesn't depend on nullglob setting, shell portability (e.g. non-Zsh), more general
cons: more complex, depends on 'find' and 'xargs'

(Probably not the best solution, but it can't hurt to know.)

Examples:

find -maxdepth 1 -name 'might-not-exist.*' -print0 \
| xargs -iZ -0 --no-run-if-empty rm Z

find -maxdepth 1 -name 'might-not-exist.*' -print0 \
| xargs -iZ -0 --no-run-if-empty ls -l Z

find -maxdepth 1 -name 'might-not-exist.*' -print0 \
| xargs -iZ -0 --no-run-if-empty echo Z


# Unrelated to the current problem, but somewhere I found it useful:
# renice Audacious if it's running
pgrep audacious | xargs --no-run-if-empty sudo renice -5

Best,
Ben



Messages sorted by: Reverse Date, Date, Thread, Author