转义文件名的方式与Bash相同 [英] Escape filenames the same way Bash does it
本文介绍了转义文件名的方式与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
这篇关于转义文件名的方式与Bash相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文