Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: printing special characters taken in command line (\")

by tye (Sage)
on May 19, 2015 at 18:46 UTC ( [id://1127169]=note: print w/replies, xml ) Need Help??


in reply to Re: printing special characters taken in command line
in thread printing special characters taken in command line

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        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1127169]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-23 18:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found