将 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/