----^--->
/\

//\\
//The\
/Sy
stem\
////
Guard
\

In the mount of the LORD it shall be seen. Genesis 22:14

AIRBORNE ON SET RIDGE - 20030122

Booming Or Fuming? | MasterCatalog | ntlib (FREE) | NTCmdLib | MtCmds | Scripts | Almost Free | TheGuardBook | Help

 

THE ANNOUNCING ISSUE - 20030101 | THE FIRING ISSUE - 20030108 | A TRIP UP THE CLIFFS OF IF - 20030115 | AIRBORNE ON SET RIDGE - 20030122 | DOWN IN THE DETAILS - 20030129 | TREASURES IN THE SAND - 20030205 | A PLAIN PATH THRU FOREST FINDSTR - 20030212

Are you Booming or Fuming?

AIRBORNE ON SET RIDGE - 20030122!

This week we complete our "Threefold Cord of Knowledge" by applying the Cord of Speed to our 29-line "Unique OS" statement, compressing the entire statement into a ONE-WORD .Mount/\Command!

Get ready to slingshot up to "SET Ridge"!


Joe Fumer has been thinking on that "Cord of Clarity" all week.
He's really starting to catch the knowledge now!

"Why didn't I start climbing before now?!", says Joe!

(Well, Joe, it's because you didn't know about .Mt/\Cmds!)

Here's our 29-line command from last week:

01. FOR /F "tokens=2 delims=." %%A IN ('VER') DO @(
02.     IF "%%A"=="0 " (
03.         (
ECHO:NT)
04.         (
SET #OS=NT)
05.         (%.SetEL0%)
06.     )
ELSE (
07.        
IF "%%A"=="00" (
08.             (
ECHO:2K)
09.             (
SET #OS=2K)
10.             (%.SetEL1%)
11.         )
ELSE (
12.            
IF "%%A"=="1" (
13.                 (
ECHO:XP)
14.                 (
SET #OS=XP)
15.                 (%.SetEL2%)
16.             )
ELSE (
17.                
IF "%%A"=="2" (
18.                     (
ECHO:K3)
19.                     (
SET #OS=K3)
20.                     (%.SetEL3%)
21.                 )
ELSE (
22.                     (
ECHO:Unknown)
23.                     (
SET #OS=Unknown)
24.                     (%.SetEL123%)
25.                 )
26.             )
27.         )   
28.     )
29. )


So far we have PROVEN our code with the Cord of Compatibility (it performs CONSISTENTLY across NT/2K/XP/K3) and ESTABLISHED it with the Cord of Clarity (each line has been explained and understood). Now we are going to send the whole segment "AIRBORNE" with the Cord of Speed!

HANG ON!

*******

The Command Interpreter (Cmd.exe) must read 29 lines of code to execute our statement. In addition, we would need to copy the entire segment into every script that requires OS-specific code.

BUT THERE'S A BETTER WAY...!

We have been careful to ensure that each command within our complex statement is enclosed in ()'s, EVEN IF THE SYNTAX DID NOT ABSOLUTELY REQUIRE IT. This is one of those CRITICAL steps that separate the FUMERS from the BOOMERS!

Now we can easily add or remove individual commands while maintaining clarity and avoiding Syntax Ditches. Recall how we used this same technique to remove lines from the SelectCase Pattern Script before applying the pattern to our example (see BoF-20030115).

However, the most significant benefit to this syntax is that we are just THREE STEPS from compressing the entire statement into ONE WORD!


STEP 1 - Combine all multi-command clauses into one line using &'s
 

01. FOR /F "tokens=2 delims=." %%A IN ('VER') DO @(
02.    
IF "%%A"=="0 " (
03.         (
ECHO:NT)&(SET #OS=NT)&(%.SetEL0%)
04.     )
ELSE (
05.        
IF "%%A"=="00" (
06.             (
ECHO:2K)&(SET #OS=2K)&(%.SetEL1%)
07.         )
ELSE (
08.            
IF "%%A"=="1" (
09.                 (
ECHO:XP)&(SET #OS=XP)&(%.SetEL2%)
10.             )
ELSE (
11.                
IF "%%A"=="2" (
12.                     (
ECHO:K3)&(SET #OS=K3)&(%.SetEL3%)
13.                 )
ELSE (
14.                     (
ECHO:Unknown)&(SET #OS=Unknown)&(%.SetEL123%)
15.                 )
16.             )
17.         )
18.     )
19. )

STEP 2 - Remove ALL LEADING WHITE SPACE (indentation) and ALL CR/LF's (the entire Complex Statement below is all on ONE LINE).

FOR /F "tokens=2 delims=." %%A IN ('VER') DO @(IF "%%A"=="0  " ((ECHO:NT)&(SET #OS=NT)&(%.SetEL0%)) ELSE (IF "%%A"=="00" ((ECHO:2K)&(SET #OS=2K)&(%.SetEL1%)) ELSE (IF "%%A"=="1" ((ECHO:XP)&(SET #OS=XP)&(%.SetEL2%)) ELSE (IF "%%A"=="2" ((ECHO:K3)&(SET #OS=K3)&(%.SetEL3%)) ELSE ((ECHO:Unknown)&(SET #OS=Unknown)&(%.SetEL123%))))))


STEP 3 - Add one more layer of ()'s around the ENTIRE One-Line Statement from Step 2.  Then load the ENTIRE STATEMENT into a .Mount/\Command using the following syntax:

    SET ".MountCommand=(YourComplexStatementHere)"

NOTE: The command below is all on ONE LINE.

SET ".GetOS=(FOR /F "tokens=2 delims=." %%A IN ('VER') DO @(IF "%%A"=="0  " ((ECHO:NT)&(SET #OS=NT)&(%.SetEL0%)) ELSE (IF "%%A"=="00" ((ECHO:2K)&(SET #OS=2K)&(%.SetEL1%)) ELSE (IF "%%A"=="1" ((ECHO:XP)&(SET #OS=XP)&(%.SetEL2%)) ELSE (IF "%%A"=="2" ((ECHO:K3)&(SET #OS=K3)&(%.SetEL3%)) ELSE ((ECHO:Unknown)&(SET #OS=Unknown)&(%.SetEL123%)))))))"


Welcome to SET Ridge!!

We now have a new "internal command" called ".GetOS". Here's the help screen:

  ^   =========================================================================
 /!\   ntlib.cmd 2002.10.18 Advanced NT/2K/XP Command Library (Freeware)
/lib\ =========================================================================

.GetOS

Displays the current OS -AND- updates #os

%.GetOS%

Also sets Errorlevels: 0=NT, 1=2K, 2=XP, 3=K3, 123=unknown


The attached Pattern Script demonstrates compressing a Complex Statement into ONE WORD, step by step (rename .txt to .cmd before running). If you are reading this as a non-subscriber, see the Scripts page to get a copy of TSG_CordOfSpeed.Pattern.cmd.


Joe is breathing Pure Mountain Air up here on "SET Ridge"!
This sure beats those Fuming Winds he was choking on down in the Foothills!

DON'T LET GO OF THAT THREEFOLD CORD, JOE!!!


.GetOS and 155 other .Mount/\Commands are included in the FREE Advanced NT/2K/XP Command Library.

The .M/\Cs that are used to set errorlevels in .GetOS are also included in ntlib.cmd.  The ".SetELn" series use only the Common Command Set to set various errorlevels.  For each .SetELn command, there is a related .ifELn command to check for EXACTLY errorlevel "n".  There is also a complete series of .ExitELn commands to exit a script (or a FOR loop) while setting a desired errorlevel.

The "Almost Free" Expert NT/2K/XP Command Library includes over 300 M/\Cs plus dozens of other Resources -AND- the $SCOUNT Function.

Here's the (abridged) help screen for $SCOUNT:

  ^   =========================================================================
 /!\   NTCmdLib.cmd 2002.10.18 NT/2K/XP ("Almost Freeware" at $9 or less!)
/LIB\ =========================================================================

$SCOUNT
VariableName|"String" VariableName|"SubString"

Count instances of Substring within String.

NTCmdLib $SCOUNT "abc123AB" "ab"

{returns _SCOUNT=2}

NTCmdLib $SCOUNT path "c:\guardpost"

{returns _SCOUNT=1 if "c:\guardpost" is present in the system path.

String and Substring ARE NOT case sensitive. ab = AB = Ab

If _SCOUNT=0 then SubString IS NOT contained within String.


The Expert Library is available for $9 or less (quantity discounts start at 5 or more).

The complete .Mount/\Command Set is also available separately for $7 or less.


All of our products are completely written using ONLY what is available in ALL INSTALLATIONS of Windows NT4 SP6a, Windows 2000, Windows XP and Windows Server 2003. There is no binary code, only scripting commands.

No install/uninstall is required, and they can be loaded from local drives (recommended), mapped drives or via UNC (\\server\share\ntlib.cmd). Everything that each script requires is already present in a default Windows installation (see Compatibility page for details).


To start receiving BoomingOrFuming?, first register, then follow the instructions on the contact page.

Space is limited and time is short, so reserve your spot today!

We'll take you up the Mountain of Knowledge, which rises higher than all the other Hills of Confusion.

/\
//\\
//
The\
/Sy
stem\
////
Guard
\
COME ON UP WITH US!
and
Congratulations On Your Decision
to
RISE ABOVE
THE REST!

^
/
!\
/LIB\

TheSystemGuard.com [Revised: 2007-03-29]
Copyright © 1995-2007, JWC
Computer Communications,
All Rights Reserved, Worldwide.
 Disclaimer       Privacy       About Us       More


Communication Is Business!

We Master It With Knowledge!

^
/
.\
/M^C\