Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Neither :: (colon colon) nor REM always starts a cmd.exe comment

19 views
Skip to first unread message

Walter Briscoe

unread,
Jun 9, 2003, 5:18:58 AM6/9/03
to
I take pleasure in writing .BAT files portable between W9X COMMAND.COM
and NTX cmd.exe. One technique, I brought with me from COMMAND.COM is
that :: (colon colon) heralds a true comment. I have just found an
example where this is not so in W2K cmd.exe. The same applies to rem.
The latter looks like a bug. The behaviour seems common to the W2K and
XP cmd.exe. Neither usage was problematic with the W95 COMMAND.COM
<
) type remcolon.bat
:: remcolon.bat
::
:: Exploration of a true comment portable between COMMAND.COM and cmd.exe
::
:: When Who What
:: 2003-06-09 W.Briscoe Original
::
@echo on
if %1.==. goto nobad0
:: Doubling % fails. Interactively, for %C in ("a;%%path%%;b) do echo %~C echoes percents and value of path
:nobad0
rem Doubling % fails. Interactively, for %C in ("a;%%path%%;b) do echo %~C echoes percents and value of path

) remcolon 1

) if 1. == . goto nobad0
The following usage of the path operator in batch-parameter
substitution is invalid: %~C echoes percents and value of path


For valid formats type CALL /? or FOR /?
The syntax of the command is incorrect.

) :: Doubling C in ("a;%path%;b) do echo %C in ("a;%%path%%;b) do echo %~C echoes percents and value of path

) remcolon

) if . == . goto nobad0
The following usage of the path operator in batch-parameter
substitution is invalid: %~C echoes percents and value of path


For valid formats type CALL /? or FOR /?
:nobad0
was unexpected at this time.

) rem Doubling C in ("a;%path%;b) do echo %C in ("a;%%path%%;b) do echo %~C echoes percents and value of path

)
>
--
Walter Briscoe

Frank

unread,
Jun 9, 2003, 10:16:42 AM6/9/03
to
Walter Briscoe <mzCeKqBC...@ponle.demon.co.uk>...

^ :: Doubling % fails. Interactively, for %C in ("a;%%path%%;b) do echo %~C


echoes percents and value of path

^ rem Doubling % fails. Interactively, for %C in ("a;%%path%%;b) do echo


%~C echoes percents and value of path

After a quick look I'd say that the problem is triggered by the appearance of
the single percent sign in "Doubling % fails." In NT, variable names can
contain spaces.

A colon indicates a label and labels may consist of variables, so the
variable name "% fails. Interactively, for %" is being expanded to an empty
string.

Frank

Pegasus (MVP)

unread,
Jun 9, 2003, 10:24:28 AM6/9/03
to

"Walter Briscoe" <wbri...@ponle.demon.co.uk> wrote in message
news:mzCeKqBC...@ponle.demon.co.uk...

While Win2000 incorrectly tries to perform a substitution on lines such as

rem %~C

Win9x is not squeaky clean either. The following line will create an empty
file test.txt even though it should not:

rem xcopy *.* d:\ >test.txt

The following line of code is another irritating trap:

if exist %temp%\semaphore.txt del %temp%semaphore.txt
if not "%1"=="" echo.>%temp%\semaphore.txt
if exist %temp%\semaphore.txt echo A parameter was passed!

You will find that semaphore.txt always exists, regardless of the existence
of a parameter!


0 new messages