我在 BASH 脚本(在 Ubuntu 12.x 下运行)中具有以下函数,它将复制文件名中包含空格的文件。它不起作用。我尝试了许多不同的组合,包括“'、\”等。我如何让它发挥作用?谢谢!
function copy_docs()
{
source_directory=/mnt/someplace
release_directory=/doc/someotherplace
cp ${source_directory}/"Some file with spaces.txt" ${release_directory}/
}
这就是我得到的输出(几乎所有排列):
cp: cannot stat `/mnt/someplace/some': No such file or directory
cp: cannot stat `file': No such file or directory
cp: cannot stat `with': No such file or directory
cp: cannot stat `spaces': No such file or directory
答案1
cp ${source_directory}/Some\ file\ with\ spaces.txt ${release_directory}/
或者
cp ${source_directory}/'Some file with spaces.txt' ${release_directory}/