Passing on an exclamation point

  • Thread starter Thread starter Csaba Gabor
  • Start date Start date
C

Csaba Gabor

How can I pass along an exclamation point?!? I have a "!=" that I
should send to a file I build up:

FOR %%G IN (%tableList%) DO (
....build up a SQL batch file...
ECHO REPLACE INTO %MapTable% >> sqlBatch
ECHO %veryUglySelectStatement% >> sqlBatch
ECHO WHERE tmp.Info!='' AND mp.Info!=tmp.Info; >> sqlBatch
....
)
REM Now execute the SQL statements
c:\mySQL\bin\mysql.exe -N Map <sqlBatch


The "!" are not sent to the batch file. I tried putting a ^ in front (which
is what
I do for a closing parenthesis in a loop to prevent the interpreter from
thinking
the loop is ending. Ie. "^)"), but this did not do the trick. I tried
using <> instead, but the interpreter didn't like that either, and I didn't
figure
out how to escape the ">" either.

My hacky workaround is to do
ECHO WHERE NOT(tmp.Info=''^) AND NOT(mp.Info=tmp.Info^); >> sqlBatch
but that's just not very satisfying. Actually, I'm interested in how to
escape characters
in general - and the specific instance (!) is the motivation.

Thanks for any tips,
Csaba Gabor
 
Csaba said:
How can I pass along an exclamation point?!? I have a "!=" that I should
send to a file I build up:

FOR %%G IN (%tableList%) DO (
...build up a SQL batch file...
ECHO REPLACE INTO %MapTable% >> sqlBatch
ECHO %veryUglySelectStatement% >> sqlBatch
ECHO WHERE tmp.Info!='' AND mp.Info!=tmp.Info; >> sqlBatch
...
)
REM Now execute the SQL statements
c:\mySQL\bin\mysql.exe -N Map <sqlBatch

The "!" are not sent to the batch file. I tried putting a ^ in front
(which is what I do for a closing parenthesis in a loop to prevent the
interpreter from thinking the loop is ending. Ie. "^)"), but this did
not do the trick. I tried using <> instead, but the interpreter didn't
like that either, and I didn't figure out how to escape the ">" either.

My hacky workaround is to do ECHO WHERE NOT(tmp.Info=''^) AND
NOT(mp.Info=tmp.Info^); >> sqlBatch but that's just not very satisfying.
Actually, I'm interested in how to escape characters in general - and the
specific instance (!) is the motivation.

You are correct: The ^ character is how you "escape" characters in cmd.exe.
However, the ! is also used in delayed variable expansion, and unlike the %
symbol, it doesn't seem like you can use "!!" to get a single "!". My guess
is that this is a shell bug. Try it without "enabledelayedexpansion."

Bill
 
Csaba said:
How can I pass along an exclamation point?!? I have a "!=" that I
should send to a file I build up:

FOR %%G IN (%tableList%) DO (
...build up a SQL batch file...
ECHO REPLACE INTO %MapTable% >> sqlBatch
ECHO %veryUglySelectStatement% >> sqlBatch
ECHO WHERE tmp.Info!='' AND mp.Info!=tmp.Info; >> sqlBatch
...
)
REM Now execute the SQL statements
c:\mySQL\bin\mysql.exe -N Map <sqlBatch


The "!" are not sent to the batch file. I tried putting a ^ in front (which
is what
I do for a closing parenthesis in a loop to prevent the interpreter from
thinking
the loop is ending. Ie. "^)"), but this did not do the trick. I tried
using <> instead, but the interpreter didn't like that either, and I didn't
figure
out how to escape the ">" either.

My hacky workaround is to do
ECHO WHERE NOT(tmp.Info=''^) AND NOT(mp.Info=tmp.Info^); >> sqlBatch
but that's just not very satisfying. Actually, I'm interested in how to
escape characters
in general - and the specific instance (!) is the motivation.

Thanks for any tips,
Csaba Gabor

- - - - - - - - - - begin screen capture - - - - - - - - - -
<Win2000> c:\cmd>demo\EchoExclamation

This is the main routine. Delayedexpansion is in effect.

REPLACE INTO XXX
SELECT * FROM SOMETABLE
WHERE tmp.Info!='' AND mp.Info!=tmp.Info;

<Win2000> c:\cmd>rlist demo\EchoExclamation.cmd
=====begin c:\cmd\demo\EchoExclamation.cmd ====================
01. @echo off
02. setlocal enabledelayedexpansion
03. set tableList=ZZZ
04. set MapTable=XXX
05. set veryUglySelectStatement=SELECT * FROM SOMETABLE
06. echo/
07. echo/This is the main routine. Delayedexpansion is in effect.
08. echo/
09. call :sub
10. type c:\temp\sqlBatch
11. goto :EOF
12. :sub
13. :: ...build up a SQL batch file...
14. setlocal disabledelayedexpansion
15. FOR %%G IN (%tableList%) DO (
16. ECHO REPLACE INTO %MapTable% >> c:\temp\sqlBatch
17. ECHO %veryUglySelectStatement% >> c:\temp\sqlBatch
18. ECHO WHERE tmp.Info!='' AND mp.Info!=tmp.Info; >> c:\temp\sqlBatch
19. )
20. endlocal
21. goto :EOF
=====end c:\cmd\demo\EchoExclamation.cmd ====================
- - - - - - - - - - end screen capture - - - - - - - - - -
 
Csaba said:
How can I pass along an exclamation point?!? I have a "!=" that I
should send to a file I build up:

FOR %%G IN (%tableList%) DO (
...build up a SQL batch file...
ECHO REPLACE INTO %MapTable% >> sqlBatch
ECHO %veryUglySelectStatement% >> sqlBatch
ECHO WHERE tmp.Info!='' AND mp.Info!=tmp.Info; >> sqlBatch
...
)
REM Now execute the SQL statements
c:\mySQL\bin\mysql.exe -N Map <sqlBatch


The "!" are not sent to the batch file. I tried putting a ^ in front
(which is what
I do for a closing parenthesis in a loop to prevent the interpreter
from thinking
the loop is ending. Ie. "^)"), but this did not do the trick. I
tried using <> instead, but the interpreter didn't like that either,
and I didn't figure
out how to escape the ">" either.

My hacky workaround is to do
ECHO WHERE NOT(tmp.Info=''^) AND NOT(mp.Info=tmp.Info^); >> sqlBatch
but that's just not very satisfying. Actually, I'm interested in how
to escape characters
in general - and the specific instance (!) is the motivation.

Thanks for any tips,
Csaba Gabor

Simply use two carats, i.e. - if you're within the context of a
delayedexpansion statement, prefix the exclamation point with ^^ as
follows -

setlocal enabledelayedexpansion
echo ^^!Hello^^!

HTH

Dean
 
Back
Top