1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

CMD's "nested quote" syntax

Discussion in 'Support' started by Christian Albaret, Mar 24, 2011.

  1. Christian Albaret

    Jul 1, 2008
    Likes Received:
    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.
  2. rconn

    rconn Administrator
    Staff Member

    May 14, 2008
    Likes Received:
    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.
  3. JohnQSmith

    Jan 19, 2011
    Likes Received:
    It is a documented feature, I discovered it the other day when trying to get a multiquoted command string to work.
    [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
    The special characters that require quotes are:
  4. rconn

    rconn Administrator
    Staff Member

    May 14, 2008
    Likes Received:
    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.)

Share This Page