linux - ls -Q 中未正确引用换行符

标签 linux bash sh ls quoting

ls -Q--quoting-style=shell 结合使用,文件名中的换行符(是的,我知道...)会变成 。这是一个错误吗?有没有办法以 100% 兼容 shell(sh 或 bash,如果可能)的格式获取文件名?

示例(bash):

$ touch a$'\n'b
$ for s in literal shell shell-always c c-maybe escape locale clocale ; do
      ls -Q a?b --quoting-style=$s
  done
a?b
'a?b'
'a?b'
"a\nb"
"a\nb"
a\nb
‘a\nb’
‘a\nb’

最佳答案

coreutils 8.25 具有新的“shell-escape”引用样式,实际上默认启用它以允许 ls 的输出始终可用,并且可以安全地复制并粘贴回其他命令。

关于linux - ls -Q 中未正确引用换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38938218/

相关文章:

linux - 迁移部署在 Linux VM 上的软件?

linux - 如何完全静音 bash 脚本的 vlc 输出?

java - 在浏览器中显示 Sh 脚本输出

linux - 为什么这个变量的一部分在与字符串组合时会被替换?

c++ - Linux C++ 程序通过系统调用启动 bash 脚本总是返回 -1

c++ - 由于比较器,Visual C++ 抛出映射异常

linux - 为什么这个 bash 代码不起作用?

bash - 从保留空格的列表创建目录

node.js - 顺序运行 npm 脚本时忽略错误

macos - 检查操作系统版本,如果版本正确则发出命令