0

What's the difference between @ an non @ command in batch script? Eg, what's the difference between @IF and IF

One more question: What's the difference between % and %% in batch script? Eg, what's the difference between %G and %%G

Thanks.

kgflying
  • 194
  • 9

1 Answers1

3

@ at the beginning of a line will execute the line but not write it to the output. It's like turning echo off just for that line. See What does @ mean in Windows Batch scripts?

%% is used in for loops inside a batch file to escape a variable name you want to "declare". For example:

for %%a in (*.txt) do ( echo %%a )

If you write the same for loop but not in a batch file, you would not double the %:

for %a in (*.txt) do ( echo %a )

I have never understood why, I just know that's the way it is. :-) Maybe someone else can elaborate.

Community
  • 1
  • 1
Nate Hekman
  • 6,507
  • 27
  • 30
  • In a batch file a single percent sign is ignored, so you need to escape them with another. – BDM Apr 04 '13 at 22:55
  • And why is a single percent ignored in a batch file but not when typed directly at the command line? What's the logic behind the different behaviour? – Nate Hekman Apr 04 '13 at 22:58
  • Found my answer: http://support.microsoft.com/kb/75634 Basically it's because batch files have the special condition of having to handle %1, %2, etc. – Nate Hekman Apr 04 '13 at 23:01