[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [PLUG] Perl backticks/system question
|
- From: "Paul W. Roach III" <paul@isaroach.com>
- To: "Philadelphia Linux User's Group Discussion List" <plug@lists.phillylinux.org>
- Subject: Re: [PLUG] Perl backticks/system question
- Date: Mon, 19 Nov 2007 15:09:29 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:references:x-google-sender-auth; bh=CqTVHEznTpSk2baejRN5+G3tem8XtVkPfklVy9B1qJc=; b=WAQ7BxBUT8pIyOgrrbzL2kwACqKpNqXBWkpgDXntA45myb6Qhyrw0zZa6pcKRTndNz2hH2juVh+9AKMS6me/t2mvijLBDKmMFh1eLSjV27A7s87QoVNktC2BpZZ9cLlwqyjC54bf5cnLiE6tqItvA2Jcm+7m79jjtnRKXFqbnJw=
- Reply-to: Philadelphia Linux User's Group Discussion List <plug@lists.phillylinux.org>
- Sender: plug-bounces@lists.phillylinux.org
I put together an example to show it:
[proach@tp ~]$ cat blah.pl #!/usr/bin/perl
use strict; use warnings;
my $input = join(" ", @ARGV);
print "input is: $input\n";
print "executing: echo $input\n"; my $output = `echo $input`; print "$output";
exit;
[proach@tp ~]$ ./blah.pl this is a test input is: this is a test executing: echo this is a test this is a test
[proach@tp ~]$ ./blah.pl this is a (test) -bash: syntax error near unexpected token `('
[proach@tp ~]$ ./blah.pl this is a \(test\) input is: this is a (test) executing: echo this is a (test) sh: -c: line 0: syntax error near unexpected token `(' sh: -c: line 0: `echo this is a (test)'
[proach@tp ~]$ ./blah.pl this is a \\(test\\) -bash: syntax error near unexpected token `('
[proach@tp ~]$ ./blah.pl this is a \\\(test\\\) input is: this is a \(test\) executing: echo this is a \(test\) this is a (test) [proach@tp ~]$
On Nov 19, 2007 3:05 PM, Paul W. Roach III < paul@isaroach.com> wrote:
Often this can take many escapes to make it work. I've seen the need to do things like:
It sounds weak, but try adding \'s until you stop getting the error :)
It's really wacky, but I've seen perl scripts calling ssh via the shell on pipes and running remote commands -- you have to escape things like 6 times -- each intermediate shell strips off half of the \ chars.
-P
At 2007-11-19 11:08 -0500, lists@linuxnotes.net < lists@linuxnotes.net> wrote:
> I have a bash script that I need to run from within a Perl script and > capture the output. My script works fine until it hits a parentheses in > an argument and then I get: > > sh: -c: line 0: syntax error near unexpected token `('
It'd help to see the code, but I think that you need to escape the parens. (Remember characters that are special for Perl will be processed and eaten within double-quotes and backticks when not escaped, but never
touched within single-quotes.) -- gabriel rosenkoetter gr@eclipsed.net
___________________________________________________________________________
Philadelphia Linux Users Group -- http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|