I am a relatively new zsh user, and love it 99% of the time. When I try to copy a bunch of files, eg:
[I] ➜ ls *17*
core.txt.17 info.17 vmcore.17.zst
but when I scp *17* xxx:xxx/xxx
, I get:
[I] ➜ scp *17* freefall.freebsd.org:
*17*: No such file or directory
ler in /var/crash at borg
[I] ➜
Why?
If I run type scp
, I get:
scp is an alias for noglob scp
scp is /usr/bin/scp
Best Answer
As you've discovered, zsh has a way to disable wildcard expansion on certain commands. If you put
noglob
before a command, zsh doesn't do wildcard expansion on the words of the command. Since typingnoglob
is often as much effort as quoting wildcard characters in arguments, the most common use is to automatically cause certain commands to be “noglobbed” by making the command name an alias to the same command name with thenoglob
prefix. For example, afteryou won't get any wildcard expansion on the
scp
command line, but other than that thescp
command will run normally.You can bypass the alias with
or
\scp
bypasses the alias and looks for a function, builtin or external command by that name.=scp
only looks for an external command.Preventing wildcard expansion for arguments of
scp
lets you writescp remote:*17*
without quotes, but it comes with the major downside of not letting you writescp *17* remote:
. It's possible to take this further and cause arguments ofscp
to have wildcards expanded only if they don't look like remote file names. Here's a function that analyzes the arguments ofscp
and only expands wildcards in arguments that don't look like options or remote file names.