Solved

escape single quote inside backticks

Posted on 2013-01-11
6
602 Views
Last Modified: 2013-12-25
$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
Comment
Question by:rgbcof
  • 3
  • 2
6 Comments
 
LVL 26

Assisted Solution

by:wilcoxon
wilcoxon earned 500 total points
ID: 38767863
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
 

Author Comment

by:rgbcof
ID: 38767880
(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
 
LVL 31

Expert Comment

by:farzanj
ID: 38767883
Try this:
my $string = "Dave's car";
$string =~ s/'/\\'/g;
print $string, "\n";
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rgbcof
ID: 38767898
that didn't work either
0
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
ID: 38767919
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
 

Author Comment

by:rgbcof
ID: 38768129
$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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Trying to install php56 on CentOS 7 get GPG error 5 39
IDE for Python 5 62
global Variable - 2 functions in powershell 1 20
AWS Linux EC2 question on group 7 7
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question