Windows 批处理脚本中的“@”是什么意思

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8486042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:00:26  来源:igfitidea点击:

What does "@" mean in Windows batch scripts

windowsbatch-file

提问by Baiyan Huang

I saw @is used in such contexts:

我看到@在这种情况下使用:

@echo off

@echo start eclipse.exe

What does @mean here?

@这里是什么意思?

回答by Joey

It means not to output the respective command. Compare the following two batch files:

这意味着不输出相应的命令。比较以下两个批处理文件:

@echo foo

and

echo foo

The former has only fooas output while the latter prints

前者只有foo作为输出,而后者打印

H:\Stuff>echo foo 
foo

(here, at least). As can be seen the command that is run is visible, too.

(至少在这里)。可以看出,运行的命令也是可见的。

echo offwill turn this off for the complete batch file. However, the echo offcall itself would still be visible. Which is why you see @echo offin the beginning of batch files. Turn off command echoing anddon't echo the command turning it off.

echo off将为完整的批处理文件关闭此功能。但是,echo off调用本身仍然可见。这就是为什么您会@echo off在批处理文件的开头看到。关闭命令回显不要回显关闭它的命令。

Removing that line (or commenting it out) is often a helpful debugging tool in more complex batch files as you can see what is run prior to an error message.

在更复杂的批处理文件中删除该行(或将其注释掉)通常是一个有用的调试工具,因为您可以看到在错误消息之前运行的内容。

回答by Jeremy McGee

It means "don't echo the command to standard output".

这意味着“不要将命令回显到标准输出”。

Rather strangely,

比较奇怪的是,

echo off

will send echo offto the output! So,

将发送echo off到输出!所以,

@echo off

sets this automatic echo behaviour off - and stops it for all future commands, too.

将此自动回显行为设置为关闭 - 并在所有未来命令中停止它。

Source: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx?mfr=true

来源:http: //www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx?mfr= true

回答by sarnold

The @disables echo for that one command. Without it, the echo start eclipse.exeline would print both the intended start eclipse.exeandthe echo start eclipse.exeline.

所述@禁用回声为一个命令。没有它,echo start eclipse.exe行会同时打印预期start eclipse.exeecho start eclipse.exe行。

The echo offturns off the by-default command echoing.

echo off关通过默认命令呼应圈。

So @echo offsilently turns off command echoing, and only output the batch author intended to be written is actually written.

所以@echo off静默关闭命令回显,只输出真正写入的批处理作者。

回答by Damien_The_Unbeliever

It inherits the meaning from DOS. @:

它继承了 DOS 的含义。@

In DOS version 3.3 and later, hides the echo of a batch command. Any output generated by the command is echoed.

在 DOS 3.3 及更高版本中,隐藏批处理命令的回显。该命令生成的任何输出都会被回显。

Without it, you could turn off command echoing using the echo offcommand, but that command would be echoed first.

没有它,您可以使用echo off命令关闭命令回显,但该命令将首先回显。

回答by Muhammad Faizan Khan

By default, a batch file will display its command as it runs. The purpose of this first command which @echo offis to turn off this display. The command "echo off" turns off the display for the whole script, except for the "echo off" command itself. The "at" sign "@" in front makes the command apply to itself as well.

默认情况下,批处理文件将在运行时显示其命令。@echo off 的第一个命令的目的是关闭此显示。命令“echo off”关闭整个脚本的显示,除了“echo off”命令本身。前面的“at”符号“@”使命令也适用于自身。

回答by Aacini

Another useful time to include @ is when you use FORin the command line. For example:

包含 @ 的另一个有用时间是FOR在命令行中使用时。例如:

FOR %F IN (*.*) DO ECHO %F

Previous line show for every file: the command prompt, the ECHOcommand, and the result of ECHOcommand. This way:

上一行显示每个文件:命令提示符、ECHO命令和命令的结果ECHO。这边走:

FOR %F IN (*.*) DO @ECHO %F

Just the result of ECHOcommand is shown.

ECHO显示命令的结果。

回答by walid2mi

you can include @ in a 'scriptBlock' like this:

您可以像这样在“scriptBlock”中包含 @:

@(
  echo don't echoed
  hostname
)
echo echoed

and especially do not do that :)

尤其不要那样做:)

for %%a in ("@") do %%~aecho %%~a