What is the at sign (@) in a batch file and what does it do?
Asked Answered
T

3

139

One remotely familiar with windows/dos batch scripting will recognize this line:

@echo off

For many-many days, I was happy with the sentiment that the @ is how echo off is meant to be written at the top of the batch and that's it.

However, recently I've came accross a line like this:

@php foo bar

and another line like this:

@call \\network\folder\batch.bat

This reinforced my suspicion that @ has more to it than just echo mode switching. However @ is not listed in the Windows XP: Command-line reference A-Z which I try to use as a reference and thus I'm not sure how to find definitive information on this:

What is the @ sign in batch, what's the terminology for it, and what does it do?

Tena answered 12/1, 2014 at 12:57 Comment(4)
Nothing to add to the ismail answer. But just for future references, the answer is included in the indicated "Command-line reference A-Z" documentation under the Remarks section of the echo command.Gum
@MCND I see, thanks! Didn't know it was echo-specific... well, I guess I misunderstood the importance of echo to batch. Here is the link to echo#remarks.Tena
I've heard it called a "squelch", but I only have anecdotal evidence for that.Nebulize
Possible duplicate of What does "@" mean in Windows batch scriptsInflame
A
203

At symbol - @

The @ symbol tells the command processor to be less verbose; to only show the output of the command without showing it being executed or any prompts associated with the execution. When used it is prepended to the beginning of the command, it is not necessary to leave a space between the "@" and the command.

When "echo" is set to "off" it is not necessary to use "@" because setting "echo" to "off" causes this behavior to become automatic. "Echo" is usually set to "on" by default when the execution of a script begins. This is the reason "@echo off" is commonly used, to turn echo off without displaying the act of turning it off.

echo verbose
@echo less verbose
pause
Asben answered 12/1, 2014 at 16:28 Comment(4)
Accepted this one for the on-site explanation of without ... any prompts associated with the execution, and for saying things like (verbosity of) the command processor, and telling about space. :) Nice test batch, too!Tena
Apparently this is obvious for everyone but I didn't know that this only works when executed from a .batfile, i.e. it doesn't work straight from the command line.Delphadelphi
When "echo" is set to "off" it is not necessary to use "@" because setting "echo" to "off" causes this behavior to become automatic. This is true. I have also found that this can cause unwanted side effects. For example - using @copy following a clip < file.txt & pause command for some reason causes my clipboard to copy the text 1 file copied.Sateia
The bad thing is I can't the official document on it!Haye
D
0

Not only does the "at" symbol placed in the beginning hide the command, it can, for some commands, also be used to append command arguments stored in a text file. The syntax is exe @commands.txt. armclang.exe for example supports this option.

Deltadeltaic answered 10/12, 2019 at 9:52 Comment(4)
No, if you try to execute something like myExe@myCommands it fails with is not recognized as an internal or external commandMistassini
@jeb, What happens when you put spaces around the @ symbol? I can't get it to work, but I've seen it used in batch files...Lawsuit
This is a (possibly common) pattern for Windows exe command-line options. armclang.exe supports this command-line option @<file> Read command-line options from <file>. Before finding this message in the help, I, too assumed this was batch code syntax. I guess I'm not accustomed to command-line options starting with @.Secondclass
This is in fact my case. Thanks.Conglobate
D
-1

So in simple terms, Mostly imagine this, If we did @echo off, It would've shown echo off right?, Well with @ you can make it so it doesn't show it, Hope this helped!

Dort answered 21/2, 2022 at 16:40 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Jubilant

© 2022 - 2024 — McMap. All rights reserved.