【发布时间】:2020-11-13 08:08:39
【问题描述】:
我在 bash 脚本中处理带有空格的文件名时遇到问题。
使用:
cat hello\ message\ \(1\).txt
成功打印文件内容。
使用:
file=hello\ message\ \(1\).txt
cat $file
返回:
cat: hello: No such file or directory
cat: message: No such file or directory
cat: '(1).txt': No such file or directory
如何在变量中存储带空格的文件名并将它们传递给命令?
【问题讨论】:
-
使用引号。
cat "$file"
标签: bash double-quotes