Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Question About %$ Alias and Batch Parameter

Jun
744
16
I don't remember noticing this before. In aliases, %$ returns the entire command tail as entered"

Code:
TCC(33.00.20): C:\commands\bat>alias zz
echo Command Tail: %$

TCC(33.00.20): C:\commands\bat>zz a=b
Command Tail: a=b

However, in a batch file, the equal sign is stripped, despite the fact that the help describes it as "the complete command tail, modified by SHIFT".

Code:
TCC(33.00.20): C:\commands\bat>type test.btm
echo Command Tail: %$

TCC(33.00.20): C:\commands\bat>test.btm a=b
Command Tail: a b

The parameter %* does work as I would expect in batch files.

Code:
TCC(33.00.20): C:\commands\bat>type test.btm
echo Command Tail: %*

TCC(33.00.20): C:\commands\bat>test.btm a=b
Command Tail: a=b

There is either a mistake in the code or a mistake in the documentation.
 
It doesn't look like that here.

Code:
type btmargs.btm
echo Command tail: %$
do i=1 to %#
    echo arg%i: %[%i]
enddo

v:\> btmargs.btm c=d
Command tail: c=d
arg1: c=d

v:\> btmargs.btm a b c=d
Command tail: a b c=d
arg1: a
arg2: b
arg3: c=d
 
I copied your script and ran it. All the equal signs were stripped. I wonder what the difference is.

I have my TCC configured not to duplicate CMD.EXE bugs. Could that be it? No, I just tried changing that.

Code:
>type test.btm
echo Command tail: %$
do i=1 to %#
    echo arg%i: %[%i]
enddo

>test.btm a=b c=d
Command tail: a b c d
arg1: a
arg2: b
arg3: c
arg4: d

Clearly there is some difference in our configurations.
 
I have CMDBatchDelimiters=No (ini directive). I reckon you have Yes.
 
I have CMDBatchDelimiters=No (ini directive). I reckon you have Yes.

I have no such directive in my INI file. I guess I've only turned off emulation of CMD bugs, not features. Ughh.

Is that something you have to insert manually? If so, in which section does it need to go?
 
I tried sticking it in the [4NT] section, and that did it.

Perhaps the above information should be in the help section about batch parameters. There is a potential difference, beyond the effect of SHIFT, between %$ and %* when that directive has not been added.
 
Does anyone know WHY '=' is a parameter separator in CMD? Can that be exploited in any way?
 
I don't know why - but I asked ChatGPT with the following result:


----- Begin ChatGPT
Why is the = char a parameter separator in windows command line/prompt (cmd)?

The = character serves as a parameter separator in the Windows Command Line (cmd) because of its historical evolution, practical utility, and legacy compatibility:
1. Historical Influence

The Windows Command Prompt traces its roots to MS-DOS, which was influenced by earlier operating systems like CP/M. These systems adopted simple and intuitive syntaxes for limited computing environments.
The use of = for parameter separation and value assignment mirrored conventions in early programming languages (e.g., BASIC) and felt natural for command-line users.

2. Assignment Syntax

The = character is a natural choice for associating names and values, making it intuitive for commands like:

SET PATH=C:\Windows\System32

This mirrors how assignment works in many programming languages, simplifying its adoption by users and developers.

3. Flexibility in Command Parsing

The use of = allows commands to distinguish between options and their associated values in cases where spaces would introduce ambiguity. For example:

FINDSTR /C:"search string"

Here, = could be used to make parameters clearer or to specify values directly:

FINDSTR /C="search string"

4. Compatibility with Legacy Tools

Many legacy tools and scripts from the MS-DOS era used = as part of their syntax. Maintaining this convention ensures backward compatibility with older systems, tools, and batch scripts.

5. Avoiding Ambiguity with Spaces

Spaces are treated as argument separators in cmd. By using =, users can avoid the need to enclose values in quotes, providing a more streamlined syntax in some cases.

6. Consistency Across Commands

Many built-in cmd commands and utilities, such as SET and ECHO, use = as a separator. This consistent usage reduces confusion and makes cmd more predictable.

Example Usage

Assigning a value to a variable:

SET VAR=VALUE

Specifying options with values:

WMIC /namespace=root\cimv2 PATH Win32_Process WHERE "Name='cmd.exe'" GET ProcessID

Conclusion

The = character as a parameter separator in cmd is a result of its historical legacy, intuitive use for assignments, and practical advantages in command-line parsing. This design choice aligns with the simplicity and flexibility needed in the Windows command-line environment.
----- End ChatGPT
 
That's more or less what Google AI comes up with. I didn't find any practical application in there. Did you?
 
Back
Top