Let me take bundle.bat
file from RubyInstaller to represent an example.
@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"ruby.exe" "C:/Ruby200/bin/bundle" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"ruby.exe" "%~dpn0" %*
I don't understand this:
- What does
@
mean here@"ruby.exe"
and what for double quotes?
Here in the manual I found some explanation:
Explanation - the first line prevents the commands from being displayed, the @ in "@echo off" keeps that line from displaying.
And here are my two test scripts.
The first one:
@ECHO OFF
@ECHO "123"
ECHO "123"
PAUSE
The output:
C:\win>batch.bat
"123"
"123"
@
does't keep line from displaying.
The second:
I want to call gem environment
command from batch file. And here I'm guided by the code from bundle.bat
file. My code:
@ECHO OFF
@"gem environment"
PAUSE
The output is an error. Please notice two double quotes:
""gem environment"" is not a command or executable or package file.
But in bundle.bat
the line @"ruby.exe" "%~dpn0" %*
works.
Now I change my script:
@ECHO OFF
REM Call like this...
@gem environment
REM or call like this.
gem environment
PAUSE
Both work fine. The output:
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.3
- RUBY VERSION: 2.0.0 (2013-02-24 patchlevel 0) [i386-mingw32]
- INSTALLATION DIRECTORY: C:/Ruby200/lib/ruby/gems/2.0.0
- RUBY EXECUTABLE: C:/Ruby200/bin/ruby.exe
- EXECUTABLE DIRECTORY: C:/Ruby200/bin
... and so on
So my questions are:
- What is the meaning of
@
character in Batch script? - When do I have to double-quote the value after
@
?