Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi
I am studying dos and I need your help:What does the following batch file line will do?
IF %1#==# GOTO
Also
In a batch file what %2 means...I really would appreaciate your help
Thank you
Ron.

Normally I don't do other people's homework for them, but I'll make an exception since this won't take long...
IF %1#==# GOTO
If %1#==# means if the variable and the # are equal to the # (which can only be if the variable %1 is not set (equals nothing). GOTO is meaningless without the word after it. GOTO EXIT would send the batch file to the line that starts with :EXIT
%1 is whatever is typed after the actual command (in the command DIR /W /S /A DIR is the command, /W is %1, /S is %2 and /A is %3. This pattern goes on up to %9 (For future reference, %0 is whater command was typed, in command above in bold, %0 would be DIR /W /S /A

The IF command compares values in a logical expression to determine a TRUE or FALSE result. If the result is TRUE, the command to the right of the IF is performed. If the result is FALSE, the IF command does nothing.
In .BAT files numbers from 1 to 9 with the percent sign (%) before them are variables representing the parameters following the .BAT file name on the command line. For exanple:
C:> mybat.bat 12 37 /s ok
Withing the MYBAT.BAT:
%1 has the value 12
%2 has the value 37
%3 has the value "/s"
%4 has the value "ok"These values replace the variable name in the command line when the command is executed. If in your example the first parameter to the command file was 93 then:
IF %1#==# GOTO
becomes:
IF 93#==# GOTO . . .
The "#" character is added so that, if there is no parameter given and %1 is null, the IF command will still have an operand on both sides of the comparison operator (==). Again, in your example, if no parameter is given and %1 in null, the IF command look like this:
IF #==# GOTO . . .
Without the "#", it would look like:
IF ==# GOTO . . .
and this would be an invalid command because there is no value on the left side of the operator.
The GOTO command causes execution of the .BAT file to jump to a label located somewhere in the .BAT file. For example:
IF %1#==# GOTO DONE
:
:
:DONE
EXITThis will test the first parameter and, if it is null, jump to the end of the .BAT file where execution ends with the EXIT command.
The GOTO command must have a label following it or will be reported as an invalid command.
Also In a batch file what %2 means...See above about parameters passed to the .BAT file.
Hope this helps.

I have written a DOS Batch File that executes a program several times, each time passing a different set of parameters.
My problem is instead of executing the first command line and waiting until the process is finished, it tries to execute the program immediately and eventually crashes.
I have been able to work around the problem using Pause, but I really don't want to have to watch it run.
Any suggestions would be appreciated.

![]() |
my 486 wont load anything
|
invalid partition table
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |