Using wildcards in commands with zsh
Solution 1
This is related with how ZSH manage globbing characters to generate filenames. By default, ZSH will generate the filenames and throw an error before executing the command if it founds no matches.
There are many ways to bypass this behavior, here are some of them:
- The quickest is to enclose the globbing characters with quotes.
$ rsync -azP "user@server:~/*" ~/
- For a permanent change, you'll have to add the following in your
.zshrc
file:
unsetopt nomatch
This will prevent ZSH to print an error when no match can be found.
- Another possibility is to disable globbing for a particular command by using the
noglob
command modifier. By setting an alias in.zshrc
for example:
alias scp='noglob scp'
Solution 2
I have been using zpretzo for quite a few months and also experienced this issue. I came across a neat and useful solution if you don't want to make any changes: simply prepend backslash to the command.
~/p/b/a/files ❯❯❯ scp *.* myserver@host:~/
*.*: No such file or directory
~/p/b/a/files ❯❯❯ \scp *.* myserver@host:~/
jquery.min.js 100% 93KB 92.6KB/s 00:00
json2.min.js 100% 3377 3.3KB/s 00:00
I hope this helps!
Solution 3
This solves your problem without having to manually quote the URLs
autoload -U url-quote-magic
zle -N self-insert url-quote-magic
# sort it out for SCP
some_remote_commands=(scp rsync)
zstyle -e :urlglobber url-other-schema \
'[[ $some_remote_commands[(i)$words[1]] -le ${#some_remote_commands} ]] && reply=("*") || reply=(http https ftp)'
Related videos on Youtube
Tirth Shah
Updated on September 18, 2022Comments
-
Tirth Shah over 1 year
I know I can download opencv-python using pip on my computer but I'm running an Anaconda server using Anaconda Navigator to run a python script. Do I need to install opencv-python via the Navigator or is it enough to download it on your machine via pip?
If not, how can I download opencv-python via the Anaconda navigator?
-
csabinho over 4 yearsPossible duplicate of Can't find package on Anaconda Navigator. What to do next?
-
-
Morgan about 11 yearsThanks! Never had to do that with
bash
. -
slhck about 11 years@Morgan That's weird, actually. Without the quotes, Bash should expand the tilde before
rsync
ever sees it. Could it be that you were just using the same path for the home directory on both servers? -
Spack about 11 years@slhck No, he's right. zsh has some more options to configure wildcards so this behavior can be changed in the zshrc.
-
sa125 about 11 years@Spack - you say it could be changes in
.zshrc
: can you elaborate a bit on how to configure this (perhaps edit your answer)? I'm looking for a way to do this without quoting the wildcard path. -
Morgan about 11 yearsAnd this goes in .zshrc?
-
Spack about 11 years@sa125 I've edited my answer.
-
Francisco about 11 yearsyes, this goes into your zsh configuration. FWIW, just start a new shell (
zsh -f
for a canonical shell conf), copy&paste the commands in your shell, and type (or paste) yourrsync
command. You'll see the magic at work ;-) (special chars at the URL will get automatically quoted) -
chepner about 11 years@slhck:
bash
only expands a tilde when it begins a word, or is the first character following a:
or the first=
in a variable assignment. Otherwise, it is treated literally. -
yorch about 7 yearsGreat solution!!
-
sMyles over 6 yearsPerfect, this worked great for me on OSX!
-
Kannan Ramamoorthy about 5 yearsAwesome!! But any reason why/how this works?