15

ZSH:

sudo apt-get remove --purge ubuntuone-* 
ERROR: zsh: no matches found: ubuntuone-*

Works on Bash. What's the problem ? :-D

13

Yes, zsh and bash behave differently in this regard.

In zsh, when you say "ubuntuone-*" it looks in your current working directory for files that start with ubuntuone- - since it does not find any, it says "no matches" and does not run the command.

bash takes a different tack - it also looks for files that start with ubuntuone- in the current working directory, but if it does not find any it says to itself, "Maybe the program I am invoking knows how to handle the wildcard," and so passes "ubuntuone-*" off to sudo apt-get as a literal argument.

If you had a file in your current working directory called ubuntuone-ffdjhjer, then bash would try to execute sudo apt-get remove --purge ubuntuone-ffdjhjer, which would probably fail.

In zsh (and in bash) you can use single quotes to tell it not to expand the wildcard but to pass it on, as in:

sudo apt-get remove --purge 'ubuntuone-*'
  • 2
    Can I make zsh behave as Bash in that manner? – mirandalol Aug 21 '13 at 13:03
  • I don't know, but the little bit of research I have done so far suggests no. In any case, it is always better (even in bash) to encase arguments in single quotes if you don't want the shell to expand wildcards, because even in bash the command won't do what you want if a file in the CWD matches the wildcard. e.g. I always type dpkg -l 'linux*' in bash to see all installed kernels. – David Purdue Aug 22 '13 at 23:56
10

Might be a little late this answer, but there is a way to fix this. From command line execute:

unsetopt no_match
  • this works great – neaumusic Oct 4 '16 at 20:35
  • Or shopt -s failglob in bash to fix bash so it behaves like zsh and other modern shells like fish or tcsh that have fixed that misfeature of the Bourne shell whereby a command may still be run even if the globs didn't match. – Stéphane Chazelas May 25 '18 at 10:53
  • @StéphaneChazelas yoda – opensourcechris Jan 19 at 14:40
1

There are another way to prevent expansion in zsh, which i prefer over quotes:

sudo apt-get remove --purge ubuntuone-\*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.