Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what does %1#==?# mean?

Status
Not open for further replies.

LesleyW

Programmer
Mar 12, 2001
196
GB
Hi folks, I hope this question belongs here, and that someone can help!

I have the following in a DOS batch file, its an installation script.
Code:
if 	%1#==?#  goto HELP
  if 	%1#==#   goto HELP
  if 	%2#==#   goto HELP
  if 	%ECOMMERCE_ROOTDIR%#==#   goto HELP
It keeps meeting the condition and going to Help, and I don't know why. I am definitely putting in 2 parameters when calling the cmd file, and I've checked that Ecommerce_RootDir environment has a valid value.

Can you please help!

 
Bad form. The pounds (#) should be exclimations (!)--there's a less likely chance that someone will type the exclimation mark. Also, in certain MS DOS versions, the HELP is an external or internal command...don't use it. Change it to something else (see below).

Try changing the following:

if %1!==MyDoc.txt! goto MyHelp
if %1!==! goto HelpMe

:MyHelp
@echo off
echo Ok this works....I'm in MyHelp now.
echo .
pause
exit

:HelpMe
@echo off
echo Good golly....I'm in the HelpME sub.
echo .
pause
exit



See if this helps any and let us know.
--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Thanks for that Miggy,lots of good advice but i am still a little confused.

First things first, I got my real life problem solved, the environment variable was not set correctly (I had it with a space between the variable name and the value, therefore the Dos Batch file couldn't see it)

For my education, what I am missing is probably so basic. . . .

What do these actually mean?
Code:
if     %1#==?#
or as you supply
Code:
%1!==MyDoc.txt!
or
Code:
if %1!==!

What do the ! or # actually represent????

TIA
Lesley

 
Think of it this way:

%1 = A (one letter ONLY!!!)

Question: Does %1==A! ( A==A! )
Answer: No. 'A' does not equal 'A!'

Explaination:
The first A doesn't have the exclaimation mark at the end.

The second A does.

We are comparing first item (in this case "A") to Second item (in this case "A!").

They do not match [red]EXACTLY[/red]!!!!


So, what to do? Well, we'll add an exclaimation mark to the first item (which is being inputed....%1!). Then, we'll compare.


%1 = A (This is being entered at the command prompt)

Now in code we'll add the ! mark for comparison.

if %1!==A! goto MatchMade

(This matches exactly. Why? we just told the computer to take the data in %1 and add an exclimation mark and compare the data in %1 (with the exclaimation added on) to the second item.

so the end result is (if you can imagine):

IF A!==A! goto MatchMade

See what's happening?
--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
You may already know this, but here goes.

The %1 is the first parameter when the batch file is called. So if the batch file is named BATCH.BAT and it is envoked by:
BATCH xyz qrs

Then xyz is %1 and qrs is %2

Thus, in your code below, the first line is checking if the batch file was invoked with the question mark as the first parameter which is usually a call for help.

The second line checks to see if there is no first parameter at all, and the third line checks if there is no second parameter at all. Thus your batch file is expecting two parameters, and if it doesn't get them, it does a goto HELP which must be a line in the batch file as follows:

:HELP

(Note the colon in front of the HELP)

if %1#==?# goto HELP
if %1#==# goto HELP
if %2#==# goto HELP
if %ECOMMERCE_ROOTDIR%#==# goto HELP


I hope this helps.

BillAtRMA

 
Thanks BillAtRMA!

I didn't have all that quite clear in my head, now it is there for next time I come to revisit these batch files.

Cheers

Lesley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top