32

This command works fine in bash:

bash-3.2$ scp luna4:/u/paige/maye/src/diviner/notebooks/plots/hk_* .
hk_az.png                                                   100%  126KB 126.0KB/s   00:00
hk_baffle.png                                               100%  166KB 166.3KB/s   00:01
hk_bb.png                                                   100%  144KB 143.8KB/s   00:00
hk_el.png                                                   100%  115KB 115.3KB/s   00:00
hk_fpa.png                                                  100%  123KB 123.2KB/s   00:00
hk_fpb.png                                                  100%  126KB 125.7KB/s   00:00
hk_hybrid.png                                               100%   99KB  98.7KB/s   00:00
hk_oba.png                                                  100%  140KB 139.7KB/s   00:00
hk_solar.png                                                100%  206KB 205.6KB/s   00:00
hk_temp.png                                                 100%   62KB  61.8KB/s   00:00
hk_yoke.png                                                 100%  122KB 121.7KB/s   00:00
bash-3.2$ exit

but in zsh it fails, no files are found:

$ scp luna4:/u/paige/maye/src/diviner/notebooks/plots/hk_* .
zsh: no matches found: luna4:/u/paige/maye/src/diviner/notebooks/plots/hk_*

What is going wrong?

0

2 Answers 2

33

The problem is that zsh is globbing the remote path. You can verify this by

scp luna4:"/u/paige/maye/src/diviner/notebooks/plots/hk_*" .

To turn globbing off for scp remote paths, but otherwise leave globbing the same (from here) add this to your .zshrc -

# Disable globbing on the remote path.
alias scp='noglob scp_wrap'
function scp_wrap {
  local -a args
  local i
  for i in "$@"; do case $i in
    (*:*) args+=($i) ;;
    (*) args+=(${~i}) ;;
  esac; done
  command scp "${(@)args}"
}
0
19

If you use single quotes, then it works:

scp 'remote.host.com:files*' .
2
  • Thank you for saving me the frustration having just switch from bash.
    – Dark Star1
    Commented Jan 19, 2022 at 11:20
  • My preferred answer. Thank you.
    – Dark Star1
    Commented Apr 25, 2023 at 7:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .