windows echo 命令在批处理编程中是如何工作的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44588260/
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
How does the echo command works in batch programming
提问by BAR Software
I'm have started to learn batch programming to go a little more deeper in the Windows Machines. In Internet I have seen some commands with echo like "@echo off"or "on"and also this: "echo."but I don't know what are they doing. If anyone can explain me the functions of the echo command, please answer me.
我已经开始学习批处理编程,以便在 Windows 机器上更深入一些。在 Internet 上,我看到了一些带有 echo 的命令,例如“@echo off”或“on”,还有这个:“echo”。但我不知道他们在做什么。如果有人可以向我解释 echo 命令的功能,请回答我。
回答by Antonio Gschossmann
The ECHO command in Windows CMD is used to print out text to the screen, display the actual setting of the Command-line which means when you do:
Windows CMD 中的 ECHO 命令用于将文本打印到屏幕上,显示命令行的实际设置,这意味着当您执行以下操作时:
@echo off
The "C:\Users[User]"line before your command input will disappear. You can restore it with:
命令输入之前的“C:\Users[User]”行将消失。您可以通过以下方式恢复它:
@echo on
Here all functions of ECHO explained:
ECHO的所有功能在这里解释:
@echo [on/off](to set the command-line settings)
echo [text](to print text to the screen)
echo.(to print an empty line to the screen)
echo(displays the current setting of the command-line)
echo /?(displays help for the command ECHO)
@echo [on/off](设置命令行设置)
echo [text](将文本打印到屏幕上)
回声。(在屏幕上打印一个空行)
echo(显示命令行的当前设置)
回声 /? (显示命令 ECHO 的帮助)
I hope I was able to help you.
我希望我能帮到你。
回答by Harun
By default, every command executed in a batch file is also echoed to the output - not just the output of the command, but the command itself.
默认情况下,批处理文件中执行的每个命令也会回显到输出 - 不仅是命令的输出,还有命令本身。
The echo command has three modes:
echo 命令具有三种模式:
- When called with some arguments AFTER a space, it will output the arguments.
- When called as
echo.
(no space) it will output just a blank line. - When called with just the arguments on or off, it controls the behaviour of printing the commands as they execute.*
- 当在空格后使用一些参数调用时,它将输出参数。
- 当调用为
echo.
(无空格)时,它只会输出一个空行。 - 当仅使用 on 或 off 参数调用时,它控制在命令执行时打印命令的行为。*
So, the echo off
command turns off the output at the start of the batch file. However, that command itself is still echoed before it has a chance to turn off the echoing. The @ symbol has the effect of turning off the output for only the current command.
因此,该echo off
命令在批处理文件的开头关闭输出。然而,在它有机会关闭回显之前,该命令本身仍然被回显。@ 符号的作用是仅关闭当前命令的输出。
Combining the two, the @echo off
at the start of a batch file turns off the echoing without itself being echoed.
将两者结合起来,@echo off
在批处理文件的开头关闭回显而不回显本身。
(* I'm not sure exactly how to output the text "on" or "off", but I suspect that using quotes around the text will change the behaviour.)
(* 我不确定如何输出文本“on”或“off”,但我怀疑在文本周围使用引号会改变行为。)
回答by lostbard
Partial answer is this: What does "@" mean in Windows batch scripts
部分答案是:Windows 批处理脚本中的“@”是什么意思
The @ before the command means do not print that command when running it.
命令前的@ 表示在运行该命令时不打印该命令。
The off argument tells the script not output any other commands, however without the @ would output the echo off (since echoing hasn't yet been turned off)
off 参数告诉脚本不输出任何其他命令,但是没有 @ 会输出 echo off(因为 echo 尚未关闭)
The on argument turns command echoing back on.
on 参数将命令回显重新打开。
Any other arguments are just echoed to the display
任何其他参数只是回显到显示器