ChatGPT解决这个技术问题 Extra ChatGPT

What does "@" mean in Windows batch scripts

I saw @ is used in such contexts:

@echo off

@echo start eclipse.exe

What does @ mean here?

Quick note: @ sign in a script suppresses the output of the corresponding command.

J
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

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 and don't echo the command turning it 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.


J
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

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


M
Muhammad Faizan Khan

By default, a batch file will display its command as it runs. The purpose of this first command which @echo off is 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.


I can't see any more or better information in your post, like in the other 5 year old posts.
For me, this was more understandable.
s
sarnold

The @ disables echo for that one command. Without it, the echo start eclipse.exe line would print both the intended start eclipse.exe and the echo start eclipse.exe line.

The echo off turns off the by-default command echoing.

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


D
Damien_The_Unbeliever

It inherits the meaning from DOS. @:

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

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


Link is now broken
A
Aacini

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

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:

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

Just the result of ECHO command is shown.


@PsychoData: It is funny that you downvoted the only answer that provide an useful information additional to the other 4 answers that, by the while, already answered the question in the same way...
I downvoted because it wasn't an answer to his question. You don't even give an explanation of what the @ does. If you have cool examples of usage, great, but it still isn't an answer to his question. You might not also know that I also upvoted the answer with the bet explanation of what it does and where it comes from. I didn't just downvote for no reason. Your "answer" is not an answer. It is a somewhat related statement.
t
terwxqian

In batch file:

https://i.stack.imgur.com/h8un3.png

2 echo off(solo)=> the “echo off” shows in the command line

https://i.stack.imgur.com/40pth.png

https://i.stack.imgur.com/GhxkA.png

https://i.stack.imgur.com/IUxl6.png

See, echo off(solo), means no output in the command line, but itself shows; @echo off(solo), means no output in the command line, neither itself;


w
walid2mi

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

@(
  echo don't echoed
  hostname
)
echo echoed

and especially do not do that :)

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