escape single quote inside backticks

$mystring = "Dave's car";
`curl $mystring http:myservice.com`;  #how to escape single quote

#I tried $string =~ s/'/\'/g; but that does not work
rgbcofAsked:
Who is Participating?
 
wilcoxonConnect With a Mentor Commented:
Unless you are using double quotes or $ characters in $mystring, changing the ' around $mystring to " on the curl line should fix the issue.

My only other idea is to try typical database escaping (which I don't think will work):

$mystring =~ s{'}{''}g; # might even need ''' - I always forget
0
 
wilcoxonConnect With a Mentor Commented:
The problem is that $mystring contains the value Dave's car (not "Dave's car").  Either of these should fix it:

$mystring = "\"Dave's car\"";

or

`curl "$mystring" http:myservice.com`;
0
 
rgbcofAuthor Commented:
(I made a  mistake on the question, here it is again)

$mystring = "Dave's car";
`curl '$mystring' http:myservice.com`;  #how to escape single quote

#I tried $string =~ s/'/\'/g; but that does not work
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
farzanjCommented:
Try this:
my $string = "Dave's car";
$string =~ s/'/\\'/g;
print $string, "\n";
0
 
rgbcofAuthor Commented:
that didn't work either
0
 
rgbcofAuthor Commented:
$string =~ s/'/'"'"'/g;  # this work.  it's shell way to escape single quote.  Sheesh.

I guess I should have posted this question in the shell group.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.