Saturday, 12 November 2016

bash - Issue with single quote within Ruby oneliner's regular expression block

I am hitting one issue after another with Ruby, single quote and double quotes today.



I have this Ruby oneliner that was used to detect whether a multiline strings exist within a file.



ruby -e 'exit(gets(nil) =~ %r{${line}} ? 0 : 1)' ${file}



It works fine until when my $line contains a single quote such as



ruby -e 'exit(gets(nil) =~ %r{This is David's car\nMazda 3\n} ? 0 : 1)' /tmp/bug8164
-bash: syntax error near unexpected token `)'


I tried to escape the single quote to the following but no luck.



ruby -e 'exit(gets(nil) =~ %r{This is David\'s car\nMazda 3\n} ? 0 : 1)' /tmp/bug8164

-bash: syntax error near unexpected token `)'


Any idea or thought? Thanks

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...