转义文件名的方式与Bash相同
问题描述:
当我在bash
中使用制表符"键时(当您开始键入文件名并希望完成时),bash
会正确转义文件名,如果我使用的是转义"文件名,它可以工作.
When I use the "tab" key in bash
(when you have started to type the filename and you want it to complete), bash
escapes the filename correctly, and if I use exactly that "escaped" filename, it works.
例如:
An-Beat - Mentally Insine (Original Mix).mp3
=> bash
之后使用"TAB"转义
An-Beat\ -\ Mentally\ Insine\ \(Original\ Mix\).mp3
An-Beat - Mentally Insine (Original Mix).mp3
=> After bash
Escapes It Using "TAB"
An-Beat\ -\ Mentally\ Insine\ \(Original\ Mix\).mp3
我正在搜索bash
的函数,该函数将以"tab"转义文件名的方式转义文件名.
I'm search for a function for bash
that will escape a filename the same way "tab" escapes filenames.
答
使用printf
(1):
x='a real \good %* load of c$rap'
x=$(printf '%q' "$x")
echo $x
将返回
a\ real\ \\good\ %\*\ load\ of\ c\$rap