32

I have switched over to zsh, and it is working fine. One strange thing, when I try to scp with a * wildcard, it does not work, and I have to drop into bash. The second command below works fine.

Any ideas on why this would be and how to fix it?

~/dmp ⌚ 16:06:10
$ scp abc@123:/home/se/exports/201405091107/* .
zsh: no matches found: root@uf3:/home/se/exports/201405091107/*

~/dmp ⌚ 16:06:53
$ bash 
sean@seanlaptop:~/dmp$ scp abc@123:/home/se/exports/201405091107/* .
0
40

The shell (both bash & zsh) tries to interpret abc@123:/home/se/exports/201405091107/* as a glob to match files on your local system. The shell doesn't know what scp is, or that you're trying to match remote files.

The difference between bash and zsh is their default behavior when it comes to failed globbing. In bash, if a glob doesn't match anything, it passes the original glob pattern as an argument. In zsh it throws an error instead.

To address the issue, you need to quote it so the shell doesn't try to interpret it as a local glob.

scp 'abc@123:/home/se/exports/201405091107/*' .

(other things like ...1107/'*' or ...1107/\* work too)

If you want to change it so the zsh no-match behavior is the same as bash, you can do the following

setopt nonomatch
2
  • 2
    Would you put the setopt nonomatch statement in .zshrc or .zprofile? I'm new to zsh. – John Mar 22 '20 at 21:45
  • 2
    Usually .zshrc – phemmer Jun 8 '20 at 1:40
3

Checkout this answer at https://superuser.com/a/740728/978073

For zprezto users, prepending the command with backslash works!

Replace,

$ scp <command>

with

$ \scp <command>
1
  • This had no effect for me \scp oldmac:~/Library/Fonts/*.* ~/Library/Fonts gives me zsh: no matches found: oldmac:~/Library/Fonts/*.* but what did work was noglob scp oldmac:~/Library/Fonts/*.* . – JamesWilson Dec 18 '20 at 21:36
0

I'm on MacOS Catalina, and the setopt nonomatch had not effect.

Solved following https://superuser.com/a/740728/978073

To make it permanent, edited ~/.zshrc :

#alias scp='noglob scp'
alias scp='\scp'

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.