CMD's "nested quote" syntax

ClearCase's cleartool command can create a process with the following command line (all on 1 line):

C:\WINDOWS\system32\cmd.exe /c ""C:\Program Files\IBM\RationalSDLC\ClearCase\bin\clearvtree" "my-source.cpp""

which shows "nested quotes". If I change COMSPEC to TCC.EXE, the command fails because TCC does not support this syntax.
 

rconn

Administrator
Staff member
May 14, 2008
12,344
149
ClearCase's cleartool command can create a process with the following command line (all on 1 line):

C:\WINDOWS\system32\cmd.exe /c ""C:\Program Files\IBM\RationalSDLC\ClearCase\bin\clearvtree" "my-source.cpp""

which shows "nested quotes". If I change COMSPEC to TCC.EXE, the command fails because TCC does not support this syntax.

I believe this is a CMD "accident" rather than a deliberate feature, since I've never seen it documented anywhere. (And since it doesn't actually do anything useful that you can't do without the quotes.)

At one time, 4NT did support this syntax, but it caused way too many problems when people passed arguments like "%var" where var didn't exist.
 
Jan 19, 2011
604
14
Norman, OK
I believe this is a CMD "accident" rather than a deliberate feature, since I've never seen it documented anywhere.

It is a documented feature, I discovered it the other day when trying to get a multiquoted command string to work.
Code:
[C:\test]cmd /?
Starts a new instance of the Windows XP command interpreter

CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
    [[/S] [/C | /K] string]

/C      Carries out the command specified by string and then terminates
/K      Carries out the command specified by string but remains
/S      Modifies the treatment of string after /C or /K (see below)

...

Note that multiple commands separated by the command separator '&&'
are accepted for string if surrounded by quotes.  Also, for compatibility
reasons, /X is the same as /E:ON, /Y is the same as /E:OFF and /R is the
same as /C.  Any other switches are ignored.

If /C or /K is specified, then the remainder of the command line after
the switch is processed as a command line, where the following logic is
used to process quote (") characters:

    1.  If all of the following conditions are met, then quote characters
        on the command line are preserved:

        - no /S switch
        - exactly two quote characters
        - no special characters between the two quote characters,
          where special is one of: &<>()@^|
        - there are one or more whitespace characters between the
          the two quote characters
        - the string between the two quote characters is the name
          of an executable file.

    2.  Otherwise, old behavior is to see if the first character is
        a quote character and if so, strip the leading character and
        remove the last quote character on the command line, preserving
        any text after the last quote character.

...

The completion code deals correctly with file names that contain spaces
or other special characters by placing quotes around the matching path.
Also, if you back up, then invoke completion from within a line, the
text to the right of the cursor at the point completion was invoked is
discarded.

The special characters that require quotes are:
     <space>
     &()[]{}^=;!'+,`~

[C:\test]
 

rconn

Administrator
Staff member
May 14, 2008
12,344
149
It is a documented feature, I discovered it the other day when trying to get a multiquoted command string to work.

Right, and TCC *does* support that behavior. What it doesn't support is the (buggy & useless) ClearCase behavior of doubling the leading & trailing quotes, and failing to provide the full executable filename (they neglected the ".exe"). (Not to mention the fact that they don't need to call CMD at all in order to run the app, but that's unfortunately a relatively common blunder.)
 
Similar threads
Thread starter Title Forum Replies Date
C Nested IF syntax — TCC behaving differently to CMD Support 12
T WAD CMD incompatibility Support 14
sully9 How to? Unexpected %DATE% CMD variable format (vs DATE /T format) in CMDebug Support 1
L FTYPE in TCC, less quirky than in cmd.exe Support 3
Peter Murschall Single-line Do-CMD is a bit uncooperative. Support 6
FreezerBurnt Help making a CMD and TCC compatible batch file Support 7
T Date format date different from cmd Support 7
D Differences between TCC and CMD with COPY /b Support 4
M Oracle batch OPatch.bat.bat not working in TCC but correctly in CMD Support 5
E TCC/CMD difference Support 5
S How to? Deinstalling TC/reinstating execution of bat files by cmd in Win7 Support 31
D How to? Pass OpenHere Folder to CMD? Support 6
R Difference between TCC and CMD: variable names with hyphens Support 4
M WAD "Pictures" directory is empty in TCC but not in CMD or Explorer Support 4
rps Cmd history recall Support 4
rps Documentation TITLE cmd docs Support 0
Joe Caverly PUSHD with UNC path in CMD.EXE Support 2
W Starting program for word to pdf conversion (difference cmd and tcc) Support 13
Joe Caverly Using this CMD technique from TCC Support 17
W If command - different with CMD Support 6
I how to make TCC default/replace cmd.exe? Support 9
R FOR usage error from TCC but not from CMD Support 16
I findstr works in cmd but not in tcc Support 5
D Pasting Unicode data has different behavior on TCC and CMD Support 2
M Command line parsing differences between cmd.exe and TCC Support 6
Joe Caverly Works with CMD.EXE, no output with TCC.EXE Support 7
Joe Caverly tcommand(cmd) Support 13
L WAD ECHO. expansion of non-existent env-vars differs from CMD.exe Support 6
Joe Caverly "Functions" in cmd.exe batch files Support 6
Joe Caverly Works in debugger, not from cmd line Support 1
K CMD, TCC, VisualStudio 2017, VcVars* differences Support 1
D Does TCC improve CMD's implementation of ECHO? Support 6
P Labels in batch files: TCC vs CMD.exe Support 9
Patulus Yet another thread on CMD compatibility Support 16
A Fixed (CMD compat) START /D fails to recognize the switch option. Support 3
Joe Caverly CMD.EXE and filename(1).ext Support 3
H DOS CMD Sort+Add Sequence+Remove Sequence number Support 12
T WAD Difference between TCC and CMD in handling multi-command lines Support 6
T CMD incompatibility Support 14
V Network share slowness vs CMD? Support 19
P Fixed Rexx .cmd files no longer work in TCC 20 Support 3
TT's Help! Uninstalling TCC did not restore cmd.exe as Win10 default batch file processor. Support 4
R How to? Display text same as in CMD Support 14
E How to? use Executable Extensions: .bat and .cmd Support 8
D Tab completion differences with cmd.exe Support 3
deleyd Fixed Behavior different than CMD Support 1
vefatica START, CMD vs. TCC Support 0
R Difference in behavior of RMDIR vs. CMD.EXE? Support 5
jogi Problem with FOR statement in TCC but not M$ CMD Support 1
C Documentation .CMD .BAT .BTM Support 15

Similar threads