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
What does "@" mean in Windows batch scripts
提问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 foo
as 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 off
will turn this off for the complete batch file. However, the echo off
call itself would still be visible. Which is why you see @echo off
in 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 off
to 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.exe
line would print both the intended start eclipse.exe
andthe echo start eclipse.exe
line.
所述@
禁用回声为一个命令。没有它,echo start eclipse.exe
行会同时打印预期start eclipse.exe
和该echo start eclipse.exe
行。
The echo off
turns off the by-default command echoing.
该echo off
关通过默认命令呼应圈。
So @echo off
silently 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 off
command, 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 FOR
in the command line. For example:
包含 @ 的另一个有用时间是FOR
在命令行中使用时。例如:
FOR %F IN (*.*) DO ECHO %F
Previous line show for every file: the command prompt, the ECHO
command, and the result of ECHO
command. This way:
上一行显示每个文件:命令提示符、ECHO
命令和命令的结果ECHO
。这边走:
FOR %F IN (*.*) DO @ECHO %F
Just the result of ECHO
command 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