你确定需要这样做吗?这是一种代码味道.除了改变你的输入之外,你很可能有更好的方法去做你想做的事情.在使用变量时正确引用变量通常就足够了:
$ file='some file name.txt'
$ touch "$file"
$ ls "$file"
some file name.txt
Run Code Online (Sandbox Code Playgroud)
但是,如果您坚持使用%qprintf 的格式:
$ str='The great theater'
$ printf '%q\n' "$str"
The\ great\ theater
$ escaped=$(printf '%q' "$str")
$ echo "$escaped"
The\ great\ theater
Run Code Online (Sandbox Code Playgroud)
请注意,这不会转义斜杠,因为它们通常不是特殊字符.
| 归档时间: |
|
| 查看次数: |
1902 次 |
| 最近记录: |