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

流过昼夜 提交于 2019-12-28 08:03:28

问题


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?


回答1:


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



回答2:


Not only does the "at" symbol placed in the beginning hide the command, it can also be used to append command arguments stored in a text file. The syntax is exe@commands (if I remember correctly)



来源:https://stackoverflow.com/questions/21074863/what-is-the-at-sign-in-a-batch-file-and-what-does-it-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!