1

I want to get the quoted string in the line below into a string exactly as-is, but I am tripping on the necessary escape sequences for Ruby. mycommand.cmd is really a wrapper for powershell.exe so I want to preserve everything between the quotes, and hold onto the escape characters that are already there.

mycommand.cmd "^|foreach-object { \"{0}=={1}\" -f $_.Name, $_.Found }"
Darshan Rivka Whittle
  • 32,989
  • 7
  • 91
  • 109
rismoney
  • 531
  • 6
  • 21

1 Answers1

4

Use single quotes :

ruby-1.9.3-p0 :001 > '^|foreach-object { \"{0}=={1}\" -f $.Name, $.Found }'
 => "^|foreach-object { \\\"{0}=={1}\\\" -f $.Name, $.Found }" 

The only escape characters in single quotes are : \' and \\

Kassym Dorsel
  • 4,773
  • 1
  • 25
  • 52
  • You double escaped the quotes, was that intentional? If not just add a % in front. – pguardiario Jun 30 '12 at 03:11
  • @pguardiario Kassym didn't double-escape the quotes, Ruby did when it responded with a representation of the same string as a double-quoted string. They are equivalent. – Darshan Rivka Whittle Jun 30 '12 at 06:53
  • Right. He didn't do it, ruby did. After he typed in the things that made ruby do that. Thanks for clearing that up ;) – pguardiario Jun 30 '12 at 07:56
  • i will accept that as answer. i was doing this for something in puppet, but somewhere else through its processing is it not treating this properly. – rismoney Jun 30 '12 at 12:06