Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

zsh seems to fail expand apt-get regular expression. For instance I would like to install all packages that has the prefix llvm-3.1, and I use:

sudo apt-get install llvm-3.1*

But zsh tells me that:

zsh: no matches found: llvm-3.1*

zsh expands other regrex well(ls * would always list all no-hidden files in the current directory).

I also tried bash or even sh(which is actually dash), and they both work right.

SO do I need to set some additional options to make zsh work for apt-get? Thanks in advance.

share|improve this question
up vote 3 down vote accepted

Those patterns are not regexps, they're commonly referred to as glob patterns. And in no case will the shell correctly expand glob patterns for package names to be used with apt-get. Shells will only expand glob patterns based on files that are present on your local file system.

The other shells that you've used also fail to expand that pattern, but rather than reporting an error they pass on the argument as typed to apt-get which then is able to match the pattern itself and do so against the names of available packages. You can get that behavior from zsh by using:

unsetopt no_match

But it would be better to get used to quoting special characters like * when you do not want those patterns to be expanded by the shell. If you happened to have a file which matched that pattern in your current directory when running that command any of those shells would expand the pattern to match that file before running apt-get, this is unlikely to give the results that you are expecting.

Any of the following would work in any of those shells, even if you have files which match the pattern:

sudo apt-get install llvm-3.1\*
sudo apt-get install 'llvm-3.1*'
sudo apt-get install "llvm-3.1*"

That would prevent the shell from trying to incorrectly expand the pattern, and for zsh it will avoid the error message if the pattern cannot be expanded.

share|improve this answer
Thanks for your answers. And sorry that I used the wrong words; I should have noted that *, ? etc. in Bash are also referred to glob. – Hongxu Chen Apr 2 '13 at 7:28
So how do you like the strategy that zsh used by default(report error message rather than pass this llvm-3.1* to apt-get)? I feel that it is not so friendly. – Hongxu Chen Apr 2 '13 at 7:37
Another possibility is to prepend the command with noglob, hence noglob sudo apt-get install llvm-3.1* should work as intended. You can define an alias for often used commands with wildcards, e.g. alias scp="noglob scp", if you don't what to change the behavior globally. (But alias won't work with sudo I suppose...) – mpy Apr 2 '13 at 8:51
I prefer that the shell report problems to me rather than silently continuing on with an interpretation that may not match what I had intended, so I much prefer the zsh handling of that. – qqx Apr 2 '13 at 13:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .