什么是单引号在Windows批处理文件吗? [英] What does single quote do in windows batch files?

查看:248
本文介绍了什么是单引号在Windows批处理文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在它与单引号CMD窗口运行命令,发现它并没有表现得如我所料。

I recently ran a command in windows cmd with single quotes in it and found that it did not behave as I expected.

从试图谷歌窗口批量单引号VS双引号我找到了几篇文章,人们问起有窗户对待单引号像双引号,以及关于如何对待庆典单引号和双引号是不同的。不过,我是不会轻易找到什么单引号的窗口批处理命令做一个明确的解释。

From trying to google "windows batch single quote vs double quote" I've found a few articles where people asked about having windows treat single quotes like double quotes, and about how bash treats single quotes and double quotes differently. However, I couldn't easily find an explicit explanation of what single quotes do in windows batch commands.

那么什么单引号在Windows批处理文件吗?难道他们都进行任何形式的报价功能?

So what do single quotes do in windows batch files? Do they perform any sort of quoting functionality at all?

推荐答案

单引号不会在所有使用的CMD.EXE命令处理器除了请将命令到FOR / F语句中运行:

Single quotes are not used at all by the cmd.exe command processor except to enclose the command to run within a FOR /F statement:

for /f %%A in ('someCommand') do ...

或指定的字符串按FOR / F处理如果使用有usebackq选项:

Or to specify a string to process by FOR /F if the USEBACKQ option is used:

for /f "usebackq" %%A in ('some string') do ...

其他由cmd.exe的引用处理的所有用双引号完成。不过,也有Windows实用程序(外部命令),如WMIC使用适合自己的报价的目的单引号。但是没有标准 - 每个工具是免费的有单引号自身间pretation

All other quoting handled by cmd.exe is done with double quotes. However, there are Windows utilities (external commands) like WMIC that use single quotes for their own quoting purposes. But there is no standard - each utility is free to have its own interpretation of single quotes.

由CMD.EXE与各种命令行工具使用的不一致逃生和报价规则,往往使得它来发现需要对任何特定情况下的正确语法的一个挑战。

The inconsistent escape and quote rules used by cmd.exe vs. various command line utilities often makes it a challenge to discover the correct syntax needed for any given situation.

下面是关于使用双引号与cmd.exe的。

Here are some important notes about using double quotes " with cmd.exe.


  • 双引号是一个简单的状态机。第一个引用轮流上,未来将其关闭。

  • Double quotes are a simple state machine. The first " turns quoting on, the next turns it off.

报价时,所有的特殊字符都被视为文字值,除了的为&LT; NEWLINE&GT; <!/ code>总是字符, 字符,如果延迟扩充被启用,而 ^ 字符如果拖延扩充被启用和也出现某处行内。

All special characters are treated as literal values when quoted, except for the % and <newLine> characters always, and the ! character if delayed expansion is enabled, and the ^ character if delayed expansion is enabled and ! also appears somewhere within the line.

如果引用是关闭的,那么你就可以逃脱 ^来$ P $从开启引述pvent它。但是,一旦报价是,你无法逃避结束。就在第二天将始终把报价关闭。

If quoting is off, then you can escape a " as ^" to prevent it from turning quoting on. But once quoting is on, you cannot escape the closing ". The very next " will always turn quoting off.

这篇关于什么是单引号在Windows批处理文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆