【问题标题】:bash cp filenames with spaces [duplicate]带有空格的bash cp文件名[重复]
【发布时间】:2018-10-25 22:07:08
【问题描述】:

我在 bash 脚本中使用变量来保存文件夹名称(迭代多个文件夹)。 我想将文件从一个复制到另一个,这些文件存在于源目录中。文件夹和文件名包含空格,所以我必须使用双引号。

例如:

#!/bin/bash
inpath="~/foo bar/"
outpath="~/temp basket/
cp "$inpath*" "$outpath" 

复制失败为:'~/foo bar/*' No such file or directory

有没有一致的方法可以做到这一点?

【问题讨论】:

  • 因为~ 如果被引用就会失去其特殊意义。

标签: bash filenames


【解决方案1】:

只引用你不想扩展或拆分的部分:

inpath=~/'foo bar'
outpath=~/'temp basket'
cp -- "$inpath/"* "$outpath"

【讨论】:

  • 非常感谢,确实成功了!
猜你喜欢
  • 2010-12-07
  • 2011-04-27
  • 2014-02-10
  • 2016-11-26
  • 2012-04-08
  • 1970-01-01
  • 1970-01-01
  • 2019-07-16
相关资源
最近更新 更多