LoginSignup
6
4

More than 3 years have passed since last update.

バッチファイルによく出てくる@echo offの意味

Posted at

最近バッチファイルを触ったのですが

@echo off

って何? と思って調べたのでアウトプット

ついでに誰かのためになったら嬉しいかも?

echo offの意味

結論から言うと、コマンドラインを見やすくするためのコマンド

こいつを付けないとファイルに書いてある文字がすべて出力されます。

echo off 付けないvar

sample.bat
set str=hello world
echo %str%
rem comment
pause

結果:

C:\Users\Sanada\Documents\BatFileTest>set str=hello world

C:\Users\Sanada\Documents\BatFileTest>echo hello world
hello world

C:\Users\Sanada\Documents\BatFileTest>rem comment

C:\Users\Sanada\Documents\BatFileTest>pause
続行するには何かキーを押してください . . .

これめちゃめちゃ見にくくないですか?
一行づつ読み込んでいくので、読み込んだ物がすべて出力されてます。

echo off 付けたvar

sample2.bat
@echo off
set str=hello world
echo %str%
rem comment
pause

結果:

hello world
続行するには何かキーを押してください . . .

必要な部分だけ出力されて非常に見やすいですね。

@にも意味があった

@echo off と echo off では結果が違う…

先に結論を言っておくと、その行を対象とするかどうかだ

@ 付けないvar

sample3.bat
echo off
set str=hello world
echo %str%
rem comment
pause

結果:

C:\Users\Sanada\Documents\BatFileTest>echo off
hello world
続行するには何かキーを押してください . . .

@ 付けたvar

sample2.bat
@echo off
set str=hello world
echo %str%
rem comment
pause

結果:

hello world
続行するには何かキーを押してください . . .

つまり下のような違いがあります
@あり:その行も対象
@なし:その行は対象外、それ以降の行から適用

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4