Skip to main content

Why does rm in zsh abort? [Resolved]

I have a number of files:

> $ ls
FleurInputSchema.xsd inp.xml              out                  usage.json
fort.77              juDFT_times.json     out.xml

and I would like to delete some of then, but not every files is there everytime. So I made an alias for

rm broyd  broyd.7 cdn* *.dat *.npy stars wkf2  fleurinputschema.xsd judft_times juDFT_times.json  inf out  out.xml  usage.json struct.xsf juDFT_times FleurInputSchema.xsd mixing_history* 2> /dev/null
zsh: no matches found: cdn*

This works fine on linux using zsh aswell. On mac it doesn't even start the rm-command, after it can't complete the cdn-wildward. How do I get zsh to ignore the missing files?


Question Credit: Stein
Question Reference
Asked June 10, 2019
Tags: terminal
Posted Under: Apple
13 views
1 Answers

With the zsh, the (very sane) default is to error on globs that can't be expanded to existing files. In other shells, the usual default is to leave the glob untouched (which may or may not be the right thing to do depending on the command - and it may very well be a very wrong thing to do). I suspect your Linux configuration has this overridden somewhere to follow the behaviour of other shells.

If you're using zsh on both shells, IMHO the best option would be to qualify globs that are allowed to expand to nothing using the (N) qualifier:

% echo .zshc*
zsh: no matches found: .zshc*
% echo .zshc*(N)

%

Of course, you can change this behaviour globally. Pick whichever of the following most suits your needs:

setopt nullglob # all globs can expand to nothing
setopt +o nomatch # leave globs as-is instead of reporting error

credit: muru
Answered June 10, 2019
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA