Zsh – Fix SCP Wildcard Not Working

scpwildcardszsh

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/* .

Best Answer

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
Related Question