53

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

3 Answers 3

80

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
  • 5
    Would you put the setopt nonomatch statement in .zshrc or .zprofile? I'm new to zsh. Commented Mar 22, 2020 at 21:45
  • 4
    Usually .zshrc Commented Jun 8, 2020 at 1:40
6

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> 
2
  • 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/*.* . Commented Dec 18, 2020 at 21:36
  • 1
    Wooowww ... thanks a lot. But how can one be expected to know that? Uff ... Commented Mar 20, 2024 at 0:18
3

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' 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.