Command Line

 


Use keywords to find the content you
are looking for with in the site.

Command Grouping

Command grouping allows one or more commands to be specified in place where only a single command is allowed. To group command together enclose all the commands in brackets (ie. ( and ) ) and separate them with the default multiple command character. There are three situations where command grouping is allowed, as follows :-

  1. At the start of a command line. For example :-
    ( ECHO one&ECHO two&ECHO three )
  2. Specifying the command parts of an IF statement. For example :-
    IF "%VAR%"=="" ( SAY nothing &ECHO found )
  3. Specifying the command part of a FOR statement. For example :-
    FOR %%J IN (*) DO ( SAY Found file &ECHO %%J )
When command grouping is used, the complete command can be split across several command lines. WinOne® will concatenate command lines until the complete command is specified. WinOne® determines that a command is incomplete, by checking for unbalanced brackets. Command grouping can be used either at the WinOne® prompt or with in a batch program. When entering commands at the WinOne® prompt and a command contains unbalanced brackets, the More? prompt is displayed, requesting more of a command. For example :-

D:\WINDOWS> IF "%VAR%"=="" (
More? SAY nothing
More? ECHO found
More? )

When a command in a batch program contains unbalanced brackets, WinOne® will simply continue to concatenate the next command line(s) in the batch program, until the complete command contains balanced brackets.

A command line can contain a maximum of 1023 characters. This includes any command lines that have been concatenated together.

When using environment variables with command grouping, they are instanciated as soon as the complete command is determined. This has a very undesirable effect. Consider the following batch program :-

SET VAR=1
IF %VAR%==1 (
SET VAR=2

ECHO %VAR%

)
ECHO %VAR%

Running the above batch program displays 1 on the first line and then displays 2 on the next line. This occurs since the first ECHO %VAR% is instanciated before the SET VAR=2 command is executed. This appears to be the standard behaviour when using brackets for command grouping (eg. CMD.EXE).

WinOne® extends command grouping to allow for delayed environment variable instanciation, by grouping commands in braces (ie. { and } ), instead of brackets. When braces are used in a command line, then any environment variables that are specified inside the braces are not instanciated, until a command, inside the braces, is about to be executed. Consider the following batch program :-

SET VAR=1
IF %VAR%==1 {
SET VAR=2

ECHO %VAR%

}
ECHO %VAR%

Running this batch program, produces the desired effect. That is, 2 is displays on both lines.

Note:

  • Command grouping using brackets and braces can be nested, repeatedly.
  • It is highly recommended to use braces instead of brackets to group commands together.

Copyright © 1995-2018 Lucien Cinc, All Rights Reserved
WinOne® is an Australian registered trademark

Go to the Australian Command Line Software web site.