strange commands please explain

  • Thread starter Thread starter Randall Flag
  • Start date Start date
R

Randall Flag

Start of batch file:

Could someone explain to me what this line is doing?

@%~d0 2>nul&cd %~p0 2>nul&call folder\start %*

i do not understand what '@%~d0 2>nul' is supposed to do also '%*'

also

@echo off&set x=@

@if not defined x echo on <- why i don't need the %x% if i is
a variable?
%x%set pfad=%~p0
%x%for %%a in (folder) do @set %%a=

thanks in advance ....
 
Randall Flag said:
Start of batch file:

Could someone explain to me what this line is doing?

@%~d0 2>nul&cd %~p0 2>nul&call folder\start %*

i do not understand what '@%~d0 2>nul' is supposed to do also '%*'

@ means "do not echo this command."

%0 means the batch file you're running. If you use ~d inside it, as %~d0,
it means "get the drive letter of this batch file." (HELP FOR for more such
options.)

2>nul means "don't display any errors." Look up "redirecting command
output" in Windows Help.

Thus,
@%~d0 2>nul
means
change drive letter to the drive letter of this batch file.

& means "append another command."

From the HELP FOR that you looked up before, you can determine that
cd %~p0 2>nul
means "change directory to the directory of this batch file."

In total,
@%~d0 2>nul&cd %~p0 2>nul
means "make sure the current directory is where the batch file is."

A slightly shorter way to do this would be
@cd /d %~dp0 2>nul

Finally, %* means "all of the arguments used when you ran this batch file."
Thus,
call folder\start %*
means find a program called "start" in a directory off the current directory
called "folder," and run it with all of the arguments you used to run this
batch file.
also

@echo off&set x=@

@if not defined x echo on <- why i don't need the %x% if i is
a variable?

Because %x% refers to the VALUE of the variable x, not the variable itself.
IF NOT DEFINED is asking whether a variable HAS a value.
%x%set pfad=%~p0
%x%for %%a in (folder) do @set %%a=

Why on earth does this script keep adding @ to everything? Why not just
start off with @ECHO OFF and be done with it?

This bit is SETting a lot of stuff, but I can see no reason for it. The
variable pfad becomes the directory path of the batch file, and the variable
folder is cleared.

David
Stardate 4653.1
 
Back
Top