By piecing together the information in the above replies, you can find your answer. But if you are impatient, here is a more direct explanation.

The Windows command shell uses the double-quote character as its quoting character. Anything that you don't want the shell to try and interpret needs to go between quotes, such as the Perl code being passed to -e. The problem you are facing comes in when you want to use a double-quote character in that Perl code. In order to do that without the shell trying to interpret it, you need to escape the character with a backslash, like you did in your second example. The reason that example fails is not because you got the shell quoting wrong, but because the Perl code is nonsensical as written. Perl is interpreting it like this:

print "
gellyfish points out in his answer that you'll need to quote the character for Perl before it will work:
print '"'
and translated for the shell:
perl -e"print '\"'"

In response to your plea to have it "just work," there's no way around it. If you wan't to use a shell's quoting character without the shell interpreting it, it needs to be escaped. This is the same for Cygwin, it just uses a different character. But if, under Cygwin, you wanted to use the single-quote character in the Perl code, you would need to escape it as well.

One last comment on printing quote characters in one-liners. Perl includes a scarcely-mentioned ability to interpret a short sequence of characters directly as a single ASCII character: v-strings. A bareword matching /v\d+/ will be translated to the ASCII character represented by the digits following the v. This is useful particularly for Windows one-liners because you can get a newline without having to double-quote anything (which, as we have seen, is painful). For example, this prints hello world with a newline:

perl -e"print 'hello world', v10"
And this prints a double-quote character with a newline:
perl -e"print v34, v10"
Note, however, that v-strings' usefulness is limited by the fact that they only work as barewords, not inside other strings. This would print v34hello worldv34 instead of "hello world":
perl -e"print 'v34hello worldv34'"
Even with that limitation, I have used them often to put newlines at the end of a print in a one-liner, although this works as well and is somewhat more readable:
perl -e"print qq[Some text ending with a newline.\n]"


In reply to Re: How do I print a quote with a perl one liner on dos? by kelan
in thread How do I print a quote with a perl one liner on dos? by tphyahoo

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.