bash 如何在 Linux 中创建带有特殊字符的文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49988312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I create files with special characters in Linux?
提问by Cameron Shirley
I am using the touch
command to try and create a file with the name "\?$*'KwaMe'*$?\"
(quotation marks included as part of the file name). However when I type touch "\?$*'KwaMe'*$?\"
in the Terminal, it doesn't give me the result I am expecting. How can I create this file?
我正在使用该touch
命令尝试创建一个具有该名称的文件"\?$*'KwaMe'*$?\"
(引号包含在文件名中)。但是,当我touch "\?$*'KwaMe'*$?\"
在终端中输入时,它并没有给我预期的结果。我怎样才能创建这个文件?
回答by Ronan Boiteau
You need to escape special characterswith the backslash symbol (\
).
您需要使用反斜杠符号 ( )转义特殊字符\
。
This command will create a file named "\?$*'KwaMe'*$?\"
:
此命令将创建一个名为的文件"\?$*'KwaMe'*$?\"
:
touch \"\\?$\*\'KwaMe\'\*$\?\\"
Explanation
解释
- Double your
\
, like this:\\
, so that your shell does not interpret the backslashes from your filename as escape characters. - Escape
"
and'
, like this:\"
,\'
, so that your shell interprets the double quotes as part of the filename. - Escape
$
, like this:\$
, otherwise your shell will think you're using a variable. - Escape
?
and*
, like this:\?
,\*
, to prevent filename expansion.