To list all docker repositories I need to use an asterisk. But I am forced to add quotes because zsh globbing catches the asterisk.

sudo docker image list "hub.local/*"

I try aliasing with noglob, but sudo will fail, and docker needs sudo

alias docker="noglob docker"

I thought I could set zsh to not complain when it fails to match, but it seems zsh will remove the asterisk anyway.

setopt nomatch

I want to either disable zsh globbing entirely, or get zsh to pass through the globbing character if it fails to match. Or possibly set zsh globbing to behave like bash. I want to get around typing quotes all the time.

  • 1
    What is the actual argument that you want to pass to docker? Is it a list of filenames or a string with a * at the end? If it's a string with a * at the end, quoting that string is the correct way of doing it. The question is otherwise a duplicate of Getting sudo to work for an alias and other similar questions. – Kusalananda Oct 7 '19 at 7:51
  • 2
    setopt +o nomatch, not setopt nomatch. – muru Oct 7 '19 at 7:53
  • @Kusalananda the argument is a string with * at the end. I don't want to use quotes! I don't want zsh globbing when I'm not specifying files – caduceus Oct 7 '19 at 8:45
  • @Kusalananda The command sudo noglob docker still fails after settings alias sudo="sudo " – caduceus Oct 7 '19 at 8:46
  • @muru this is the answer, thanks – caduceus Oct 7 '19 at 8:47
alias docker='noglob sudo docker'

Would cause globs to never be expanded on a line that starts with docker and would run docker under sudo. If you still occasionally need to run docker not as root, you could make it a sudo-docker or sdocker alias instead.

I wouldn't recommend enabling the Bourne/bash behaviour which is really a bad design and is dangerous, but it you really wanted to, that could be done with set +o nomatch (or setopt nonomatch or unsetopt nomatch...).

|improve this answer|||||

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