[英]Missing putting quote " symbol into file from windows command line or batch
I am trying to write different things to a text file from a .bat file. 我正在尝试从.bat文件向文本文件中写入不同的内容。 At every attempt to insert one quote "
it results in avoiding this command, well, it looks like because it is missing "
the symbol in an output file. 在每一个试图插入一个报价"
它导致了避免这种命令,那么,它看起来像,因为它缺少"
符号在输出文件中。 Here is what I am trying to do: 这是我正在尝试做的事情:
echo ' " '>> file.txt
It does not even work if we simply try it from CLI 如果我们只是从CLI尝试,它甚至无法工作
echo ' " '> file.txt
I had the same issue with printf
and echo
from MinGW. 我在printf
和MinGW的echo
也遇到了同样的问题。 What is wrong here? 怎么了
You need to escape some special characters to treat them literally. 您需要转义一些特殊字符才能按字面意义对待它们。 Particularly, "
double quote toggles the quote flag , if the quote flag is active, the following special characters are no longer special: ^
&
|
<
>
(
)
. 特别是, "
双引号切换引号标志 ,如果引号标志处于活动状态,则以下特殊字符不再特殊: ^
&
|
<
>
(
)
。
==> echo ' " '>> file.txt
' " '>> file.txt
==> type file.txt
The system cannot find the file specified.
==> echo ' ^" '>> file.txt
==> type file.txt
' " '
Next script shows some escaping rules for ECHO
command; 下一个脚本显示了ECHO
命令的一些转义规则; note different output (and rules for caret and exclamation mark ) if Delayed Expansion is disabled or enabled: 如果禁用或启用了延迟扩展,请注意不同的输出(以及插入符号和感叹号的规则):
@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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.