在cmd命令行中使用引号和其他特殊字符
我经常使用命令行工具,有时我会和解释器争论如何解释参数边界,然后使用引号 例如:在cmd命令行中使用引号和其他特殊字符,cmd,escaping,Cmd,Escaping,我经常使用命令行工具,有时我会和解释器争论如何解释参数边界,然后使用引号 例如: grep -r "#include" . | perl -pe "s/.*?#include.*?[\"<](.*?)[\">].*/\1/" 我想从子目录中的所有文件中提取一个包含所有内容的列表。问题似乎是cmd只接受双引号。因为它们也是正则表达式的一部分,所以我必须在那里避开它们。但这似乎不起作用。由于将尖括号误解为输入重定向运算符,因此InExperiter抱怨文件名方案无效。使用反斜杠似乎不
grep -r "#include" . | perl -pe "s/.*?#include.*?[\"<](.*?)[\">].*/\1/"
我想从子目录中的所有文件中提取一个包含所有内容的列表。问题似乎是cmd只接受双引号。因为它们也是正则表达式的一部分,所以我必须在那里避开它们。但这似乎不起作用。由于将尖括号误解为输入重定向运算符,因此InExperiter抱怨文件名方案无效。使用反斜杠似乎不起作用
有谁能给我一些建议/提示/帮助来解决这个问题吗?除了安装替代外壳之外
提前感谢。编辑。下一个命令行示例可能会让它更加了解echo返回的字符串与您在问题中提供的字符串相同:
==>echo "s/.*?#include.*?[\"^<](.*?)[\">].*/\1/"
"s/.*?#include.*?[\"<](.*?)[\">].*/\1/"
阅读。在下一批.bat脚本中,您可以看到一些示例:
@setlocal
@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
@setlocal enabledelayedexpansion
@Echo ^^! - Exclamation Mark: to mark delayed expansion environment variables ^^!var^^!
@endlocal
@setlocal disabledelayedexpansion
@Echo ^! - Exclamation Mark: to mark delayed expansion environment variables ^!var^!
@endlocal
@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 "http://judago.webs.com/batchoperators.htm"
@endlocal
@rem pause
@GOTO :eof
这可能会应用于未测试的批处理,但似乎不会对正常的命令行更新有任何影响-它似乎可以工作。这意味着双引号根本不必转义,方括号中的反斜杠不属于表达式?但是如果它们不必转义,为什么解析器解释
@setlocal
@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
@setlocal enabledelayedexpansion
@Echo ^^! - Exclamation Mark: to mark delayed expansion environment variables ^^!var^^!
@endlocal
@setlocal disabledelayedexpansion
@Echo ^! - Exclamation Mark: to mark delayed expansion environment variables ^!var^!
@endlocal
@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 "http://judago.webs.com/batchoperators.htm"
@endlocal
@rem pause
@GOTO :eof