[Date Prev][Date Next][Subject Prev][Subject Next][ Date Index][ Subject Index]

Re: Autoexec.nt commands



** Reply to message from Harry Binswanger  on
Thu, 23 Aug 2007 16:48:10 -0400


> Re Robert's CHOICE.BAT using SET /P
> It works. I got a strange result when I hit ENTER
> instead of responding with y/N:
> Yes was unexpected at this time.

The ONLY reason you got that is that you did NOT follow my
template and example! So don't misrepresent it as "Robert's
CHOICE.BAT", because your code is NOT my example CHOICE.BAT.
Don't leap to negative conclusions! My code is more than the snippet I put
in my email. I used your whole program--I simply copied and pasted it into
a file I named it TEST.BAT.
 I don't know what your code says, but it isn't the same. It seems
to me that when you're LEARNING, you don't "do it your way" and
omit the things you don't understand, and then ask why the whole
doesn't work. If you'd started with my example, you wouldn't
get that "strange" result.


And here's the code I ran, copied and pasted from TEST.BAT:

@echo off
::CHOICE.BAT
::Works w/Win95CMD (KMD.EXE) ergo cross-platform
set /p oui=Respond Yes or No (y/N):
if %oui%!==! set oui=N
if %oui%==y set oui=Y
if %oui%==Y echo OK
if not %oui%==Y echo Not OK
 Therefore variable OUI
was empty. Therefore "y is unexpected" because variable OUI
doesn't exist. Something that doesn't exist cannot equal "y"
and may be said to be utterly "unexpected".

Ahh, I see now. But how come I got that from running what I copied and pasted?
It happened the first time I ran it, so it was not from any modification on my part. Whatever it was, TEST.BAT runs as advertised now.
You MUST include code to trap an empty/nonexistent VARIABLE if
you intend further evaluation. And that's why the *first* line
after SET /P is:
 if %oui%!==! set oui=N

Good point.
If %oui% doesn't exist, then "!" will equal "!". Put another
way, if "!" equals "!" then %oui% MUST necessarily be null.
It's a simple equation.
Oh, I see. Then the "!" has no special meaning. It could be any symbol (or
string), because %oui%! performs a concatenation? Yes, I tested it with an
arbitrary string on both sides of the "==" and it did work (yes, I nulled
out the variable beforehand).
≫ if %oui%==y set oui=Y

> ... Interestingly, the user-response is not case-sensitive.
> I.e., Y and y produce the same "OK."

Isn't the line you quote self-evident? The line means: "if OUI
= y then OUI = Y". It uppercases user's response,
Yes, I see. I'm only faintly familiar with variables in batch files, so I
didn't know how to read that. I still don't understand the shift between
%oui% and oui. Why isn't it always %oui%? Is it the use/mention thing:
%oui% refers to the value of the variable. But then so does oui in "set
oui=Y"--or does it? Hmmm. If the content of the variable is "y" then you
can't alter the content qua fact about the world, you can only re-direct
the variable to point to a different fact. Is that it? If the variable is
storing a certain letter of the alphabet, you can't change the alphabet
itself, nor do you intend to, but you can direct the variable to store a
different item. So %oui% denotes the referent of "oui" and "oui" denotes
the variable-qua-storer?
If that's right, why do BASIC and XPL not need to make that kind of
distinction? In BASIC you can write:

Let A$ = "y"    ---- 'let' is, of course, archaic, but BASIC once used it
If A$ = "y" then A$ = "Y"

In XPL:
≪SV01,y≫;*;
≪IF≪IS01≫=="y"≫≪SV01,Y≫≪EI≫

Or is ≪IS...≫ making some sort of use/mention distinction? And ≪PV...≫?
This is what I was complaining about a few weeks ago: hitting
the Help button instead of struggling and thinking first, and
thereby shifting the burden -- creating unnecessary burden -- as
well as sowing doubt in the minds of hundreds of subscribers
that a pie-simple & nearly braindead procedure may not be as
easy as it looks. That there may be "unexpected wrinkles"!
Really irritating. Because actually, you just botched it --
willfully!
Mea non culpa! I swear that I pasted in the code you wrote--all of it. BTW,
I wasn't asking for *help* on the "y unexpected . . ." issue. I said the
batch file works. I merely reported it as a strange result. What I asked
for help (explanation) on was the meaning of

if %oui%!==! set oui=N

--a statement whose meaning we don't all take in with mother's milk.
But, Robert, I recognize that all of this is you doing me (and maybe some others) a *favor*. This wasn't even a Xy issue. So if it's burdensome, I apologize.


Harry Binswanger
hb@xxxxxxxx