Welcome!

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

SignUp Now!

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.
 
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.
 
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]
 
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

Replies
0
Views
1K
Back
Top