簡體   English   中英

從Windows命令行或批處理缺少將引號“符號放入文件中

[英]Missing putting quote " symbol into file from windows command line or batch

我正在嘗試從.bat文件向文本文件中寫入不同的內容。 在每一個試圖插入一個報價"它導致了避免這種命令,那么,它看起來像,因為它缺少"符號在輸出文件中。 這是我正在嘗試做的事情:

echo ' " '>> file.txt

如果我們只是從CLI嘗試,它甚至無法工作

echo ' " '> file.txt

我在printf和MinGW的echo也遇到了同樣的問題。 怎么了

您需要轉義一些特殊字符才能按字面意義對待它們。 特別是, " 雙引號切換引號標志 ,如果引號標志處於活動狀態,則以下特殊字符不再特殊: ^ & | < > ( )

==> 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM