From: Eric Hodel Date: 2011-02-10T08:55:15+09:00 Subject: Re: System calls with ` in parameters On Feb 9, 2011, at 3:48 PM, Gerad S. wrote: > Hi All, > > I am trying to add functionality to an interesting script. The part > that is tripping me up is that I have to make a system call to echo, and > feed several parameters. One of the parameters occasionally includes > the ` character. > > Because of this, the syntax of: > > `echo "#{someVar}" | ./some-script.py > "#{outputFile}"` > > is breaking when #{someVar} contains the tick `. This causes the > command to fail because it executes up to the tick ` in someVar and not > to the end as intended. > > I have also tried using the system() command as follows: > > system("echo \"#{someVar}\" | ./some-script.py > \"#{outputFile}\"") > > But this fails when there is a tick ` in #{someVar} as well. > > Any help would be appreciated. Shellwords should do it: ruby -rshellwords -e 'p Shellwords.escape "`"'