I want to use backticks in ruby for a programm call. The parameter is a String variable containing one or more backticks, i.e. "&E?@@A`?". The following command yields a new label as its return value:
echo "&E?@@A\`?" | nauty-labelg 2>/dev/null
From a ruby program I can call it as follows and get the correct result:
new_label = `echo "&E?@@A\\\`?" | nauty-labelg 2>/dev/null`
I want to achieve the same using a variable for the label. So I have to insert three slashes into my variable label = "&E?@@A`?" in order to escape the backtick. The following seems to work, though it is not very elegant:
escaped_label = label.gsub(/`/, '\\\`').gsub(/`/, '\\\`').gsub(/`/, '\\\`')
But the new variable cannot be used in the program call:
new_label = `echo "#{escaped_label}" | nauty-labelg 2>/dev/null`
In this case I do not get an answer from nauty-labelg.