从Windows命令行或batch file中丢失引号“符号

我正在尝试从.bat文件中将不同的东西写入文本文件。 在每一个插入一个引号的尝试中, "它避免了这个命令,看起来好像是因为缺less了输出文件中的符号" 。 这是我正在做的事情:

 echo ' " '>> file.txt 

如果我们只是从CLI中尝试它,它甚至不能工作

 echo ' " '> file.txt 

我和MinGW的printfecho有同样的问题。 这里有什么问题?

你需要逃避一些特殊的字符来对待他们。 特别是, " 双引号”会切换报价标志 ,如果报价标志处于激活状态,则下列特殊字符不再是特殊的: ^ & | < > ( )

 ==> echo ' " '>> file.txt ' " '>> file.txt ==> type file.txt The system cannot find the file specified. ==> echo ' ^" '>> file.txt ==> type file.txt ' " ' 

下一个脚本显示了ECHO命令的一些转义规则; 如果延迟扩展被禁用或启用,请注意不同的输出(以及脱字符感叹号规则):

 @cls @setlocal disabledelayedexpansion @Call :ouputOnly @endlocal @Echo . @setlocal enabledelayedexpansion @Call :ouputOnly @endlocal @GOTO :eof :ouputOnly @Echo ^@ - At Symbol: be less verbose @Echo ^~ - Tilde: Parameter Expansion as in Call subroutines, FOR loops etc. @Echo ^& - Single Ampersand: used as a command separator @Echo ^&^& - Double Ampersand: conditional command separator (if errorlevel 0) @Echo ^|^| - Double Pipe: conditional command separator (if errorlevel ^> 0) @Echo ^:^: - Double Colon: alternative to "rem" for comments outside of code blocks @Echo ^^ - Caret: general escape character in batch @Echo ^" - Double Quote: surrounding a string in double quotes @Echo escapes all of the characters contained within it @Echo ^() - Parentheses: used to make "code blocks" of grouped commands @Echo %% - Percentage Sign: are used to mark three of the four variable types @Echo ^^! - Exclamation Mark: to mark delayed expansion environment variables ^^!var^^! @Echo ^* - Asterisk: wildcard matches any number or any characters @Echo ^? - Question Mark: matches any single character @Echo ^. - Single dot: represents the current directory @Echo ^.. - Double dot: represents the parent directory of the current directory @Echo ^\ - Backslash: represent the root directory of a drive dir ^\ @Echo ^| - Single Pipe: redirects the std.output of one command @Echo into the std.input of another @Echo ^NUL (File like device): is like a bottomless pit @Echo ^CON (File like device): is a file like device that represents the console @Echo ^> - Single Greater Than: redirects output to either a file or file like device @Echo ^>^> - Double Greater than: output will be added to the very end of the file @Echo ^< - Less Than: redirect the contents of a file to the std.input of a command @Echo Stream redirection: regarding the less and greater than symbols @echo caret^^ "caret^" @echo caret^^^^ bang^^! "caret^^ bang^!" @exit /B @rem based on (dead link nowadays) http://judago.webs.com/batchoperators.htm