I am building a string that will be used as a command run on a Windows box over SSH.
The command must be executed with elements of it wrapped in double quotes, so I have to wrap the command as a whole in single quotes. However this means I lose the ability to use inline interpolation.
So Is there a way I can still use inline interpolation on a single-quoted string?
Use %Q{command} as follows:
puts %Q{Hello "xyz"} => Hello "xyz"
puts %Q{"Hello" 'xyz'} => "Hello" 'xyz'
No, you can't use interpolation with single-quoted string. You can, instead, escape double quotes.
puts "I say \"Hello\""
# >> I say "Hello"
puts %Q(I say "Hello", you say #{goodbye})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.