Under Windows CMD.EXE, you would instead use double quotes ("), unless that happened to be one of the characters you wanted to pass through, in which case (IIRC) you would need to use two double quotes ("").

Actually, \" is the most common. Unfortunately, there is not one universal answer as each command can choose to interpret its command line differently (because it isn't CMD.EXE that breaks the command line into arguments and thus handles the quotes as would be the case with a Unix shell). But it seems that following how C does it has become pretty common.

See Re^2: The Evil Embedded Space (system(@list)) for more details and example implementation. One thing I failed to note in that node is that you get extra divergence in interpretation if you produce something that contains a double quote but doesn't match:

/^"( [^\\"]+ | \\+[^\\"] | (\\\\)*\\" )*"$/x

That regex may be easier to understand if I write it in a fictional version of Perl where \ is not used to escape regex meta-characters:

/^"( [^\"]+ | \+[^\"] | (\\)*\" )*"$/x

So, indeed, you can sometimes get what you desire by using doubled double quotes. One convenient way to test how C splits up arguments is:

C:\> perl -le"print for @ARGV" hi "hi" "\"hi\"" "\\hi\\" "\\hi\\\"" hi hi "hi" \\hi\ \\hi\"

That lets one see how "...""..." works while how trying to include two literal quotes that way can fail:

C:\> perl -le"print for @ARGV" "6""5'" 6"5' C:\> perl -le"print for @ARGV" "say ""hello"" to my little friend" say "hello to my little friend

- tye        


In reply to Re^2: printing special characters taken in command line (\") by tye
in thread printing special characters taken in command line by bagana14

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.