What does “@” mean in Windows batch scripts

前端 未结 7 1650
遥遥无期
遥遥无期 2020-12-02 07:12

I saw @ is used in such contexts:

@echo off

@echo start eclipse.exe

What does @ mean here?

相关标签:
7条回答
  • 2020-12-02 07:14

    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
    
    0 讨论(0)
  • 2020-12-02 07:16

    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.

    0 讨论(0)
  • 2020-12-02 07:17

    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.

    0 讨论(0)
  • 2020-12-02 07:24

    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

    0 讨论(0)
  • 2020-12-02 07:28

    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.

    0 讨论(0)
  • 2020-12-02 07:31

    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.

    0 讨论(0)
提交回复
热议问题