38

zsh使用scp命令时*通配符出现no matches的错误 - tlanyan

 4 years ago
source link: https://www.tlanyan.me/zsh-scp-star-error-no-matches/?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

zsh使用scp命令时*通配符出现no matches的错误

Linuxtlanyan2020年4月25日

MacOS升级后zsh成了默认的shell,顺应潮流开始了zsh的使用之旅。

今天使用scp复制远程多个文件时出现如下错误:

# 复制某个目录下的所有配置文件(*.conf)
scp host:/xxxx/*.conf .
# 错误如下错误
# zsh: no matches found: host:/xxxx/*.conf

很肯定这条命令语句在bash中能正常如期工作,出现这样的问题应该是zsh的锅。作为资深linux用户,可以很快看出了问题所在:zsh试图将*通配符展开,在本地未找到对应文件,于是出现“no matches”的错误。

经过个人尝试以及网上搜索,有两种解决方案:

  1. 不要让zsh将*号展开;具体做法有:
    • 将*号部分用引号引起来,单双引号都所无谓。例如:scp "host:/xxxx/*.conf" .,或者scp 'host:/xxxx/*.conf' .。也可以只引用路径部分,例如:scp host:'/xxxx/*.conf' .
    • 用反斜杆阻止zsh转义:scp host:/xxxx/\*.conf .
  2. 设置nonomatch选项,让zsh匹配失败时不报错并使用原本内容。具体做法是:setopt nonomatch,然后再使用scp命令。推荐的做法是写入到.zshrc文件中,让以后的使用中自动生效。
  1. zsh使用scp命令时*通配符无法使用

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK