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

NEWS. (That begins with... and about value is named variable).

4 views
Skip to first unread message

Benny Pedersen

unread,
Mar 26, 2002, 1:09:25 AM3/26/02
to

NEWS. (That begins with... and about value is named variable).
Is not uploaded http://users.cybercity.dk/~bse26236/

Hi,

@ECHO OFF

SET VAR=Test

FOR %%2 in (.2) do IF %%%VAR%==.%VAR% ECHO %VAR% begins with 2
FOR %%T in (.T) do IF %%%VAR%==.%VAR% ECHO %VAR% begins with T
FOR %%t in (.t) do IF NOT %%%VAR%==.%VAR% ECHO %VAR% begins NOT with t

The above syntax is much faster than echoing | CHOICE with use
of a pipe.

So, if one would create a script something like this:

@ECHO OFF
%1 SET VAR=Test
%COMSPEC%/c%0 GOTO:_SCR|debug> Output

FOR %%c in (TYPE DEL GOTO:EOF) do %%c Output
:_SCR
PROMPT e100'%VAR% '$_ D100 L1 $_quit
FOR %%c in (ON OFF) do ECHO %%c
:EOF

Then a script named Output would contents the following lines:
==============================================================
-
-e100'Test '
- D100 L1
107E:0100 54 T
-quitECHO OFF
==============================================================
4 lines of output got a prefix of a hyphen namely the commands
but the resulting line didn't got a hyphen (the line which say
that the ACSII value of T is 54 hex).

To remove the used commands, we usual did something like this:

%COMSPEC%/c%0 GOTO:_SCR|debug|find /v "-"> Output
or %COMSPEC%/c%0 GOTO:_SCR|debug> Output
using an extra line: find ":" < Output > New_Output

The extra line is obvious used to avoid the pipe, or
is used to make it better readable.

It is possible to use the Output without piping |find
as shown above with use of an extra line but it could
also be done without using the find.exe,

Since debugs commands begins with a hybhen but
the result NOT, then

rewriting
FOR %%T in (.T) do IF %%%VAR%==.%VAR% ECHO %VAR% begins with T

to this
FOR %%- in (.-) do IF %%%2==.%2 GOTO EOF (begins with hyphen).

Now that I have introduced the new
"Value of variable begins with X" technique, then I
would also show you this new one:

SET D%3=D%3

A variable named D%3 got the value of its own name.

How does it works?

After a Script is written and debugged, then we got
something like this:

-command1 blah
-command2
result

So we need to prefix a PROMPT. For example:
PROMPT CALL %0 GOTO:BAT =

result:

CALL %0 GOTO:BAT =-command1 blah
CALL %0 GOTO:BAT =-command2
CALL %0 GOTO:BAT =result

If one of the used commands contains an extra element
as the blah in "-command1 blah", then that extra parameter
can be used as %3.

-command1 would become %2
and blah would become %3

See the batch file below.

Benny Pedersen,
PS. The
FOR %%c in (ON OFF) do ECHO %%c
used in the first script example in line 21 above,
can often be used instead of
ECHO ON
% blank line%
@ECHO OFF
but not in this example,

@ECHO OFF
%1
%COMSPEC%/c%0 GOTO:SCR> %temp%.\$.SCR
debug > %temp%.\$.bat < %temp%.\$.SCR

%COMSPEC%/c%0 GOTO:PREFIX

MOVE %temp%.\$.scr %temp%.\$.BAT> NUL
FOR %%c in (CALL DEL) do %%c %temp%.\$.BAT

ECHO. Century/Year/Month/Day %D32% %D9% %D8% %D7%
FOR %%c in (7 8 9 32) do SET D%%c=
:: for %%c in (pause cls set goto:eof rem:-) do %%c
GOTO EOF ^^^

:SCR
PROMPT o70,7$_i71$_o70,8$_i71$_o70,32$_i71$_o70,9$_i71$_q
ECHO ON
,
@ECHO OFF
GOTO EOF

:PREFIX
PROMPT CALL %0 GOTO:BAT =
CTTY NUL
COMMAND /c%temp%.\$.BAT > %temp%.\$.SCR
GOTO EOF

:BAT
IF NOT ()==(%3) SET D%3=D%3
FOR %%- in (.-) do IF %%%2==.%2 GOTO EOF
FOR %%c in (%D7% %D8% %D32% %D9%) do SET %%c=%2
:EOF

John Savage

unread,
Mar 29, 2002, 6:55:50 PM3/29/02
to
"Benny Pedersen" <b.ped...@get2net.dk> writes:
> SET VAR=Test
>
> FOR %%2 in (.2) do IF %%%VAR%==.%VAR% ECHO %VAR% begins with 2
> FOR %%T in (.T) do IF %%%VAR%==.%VAR% ECHO %VAR% begins with T
> FOR %%t in (.t) do IF NOT %%%VAR%==.%VAR% ECHO %VAR% begins NOT with t

You come up with some good ideas, Benny. I'm not sure why you have
introduced the dots into the test; they seem to be unnecessary.

Where the string %VAR% contains spaces, the above will fail because any
spaces after the "==" operator are interpreted as the string delimiter.
In such cases, I think this alternative would be more generally successful:
FOR %%T in ("T ") DO IF %%%VAR%==%%T ECHO %VAR% begins with T
FOR %%t in ("t ") DO IF %%%VAR%==%%t ECHO %VAR% begins with t
--
John Savage (for email, replace "ks" with "k" and delete "n")

Benny Pedersen

unread,
Mar 30, 2002, 2:59:35 AM3/30/02
to

"John Savage" <rook...@suburbian.com.au> wrote news:020330000105728.30Mar02$rook...@suburbian.com...

> "Benny Pedersen" <b.ped...@get2net.dk> writes:
> > SET VAR=Test
> >
> > FOR %%2 in (.2) do IF %%%VAR%==.%VAR% ECHO %VAR% begins with 2
> > FOR %%T in (.T) do IF %%%VAR%==.%VAR% ECHO %VAR% begins with T
> > FOR %%t in (.t) do IF NOT %%%VAR%==.%VAR% ECHO %VAR% begins NOT with t
>
> You come up with some good ideas, Benny. I'm not sure why you have
> introduced the dots into the test; they seem to be unnecessary.

No. The problem is that it would fail variable = blank.

:: fails single space AND blank,
SET VAR=
FOR %%T in (T) do IF NOT %%%VAR%==%VAR% ECHO T not

> Where the string %VAR% contains spaces, the above will fail because any
> spaces after the "==" operator are interpreted as the string delimiter.
> In such cases, I think this alternative would be more generally successful:
> FOR %%T in ("T ") DO IF %%%VAR%==%%T ECHO %VAR% begins with T
> FOR %%t in ("t ") DO IF %%%VAR%==%%t ECHO %VAR% begins with t

Yes, the above could also be used. My following pairs as in the
original message as well,


> > FOR %%T in (.T) do IF %%%VAR%==.%VAR% ECHO %VAR% begins with T
> > FOR %%t in (.t) do IF NOT %%%VAR%==.%VAR% ECHO %VAR% begins NOT with t

A leading space, SET VAR= Testing, don't begins with T but
begins with a space.
(To let the value of VAR begin with T instead of a space,
you would do something like this:
SET VAR= Testing
FOR %%C in (%VAR%) do SET VAR=%%C
)

Unwanted space in parameters are lost when used of recursive files.

A version without the dots would fails both single space AND value = blank.

Benny Pedersen,
PS.
Your post toke some time to get from Suburbian to here :-)


0 new messages