Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: sh: -c: line 1: syntax error near unexpected token `|'

by cdarke (Prior)
on May 10, 2012 at 09:23 UTC ( #969778=note: print w/ replies, xml ) Need Help??


in reply to Re^2: sh: -c: line 1: syntax error near unexpected token `|'
in thread sh: -c: line 1: syntax error near unexpected token `|'

Probably better to place quotes around the command, for example:

$cmd = "'------------- Hello World ------------'";
or use somthing like q()

Also, you might like to use "end of options":
my $result = `echo -- $cmd | grep -- '\-\-\-\-'`;


Comment on Re^3: sh: -c: line 1: syntax error near unexpected token `|'
Select or Download Code
Replies are listed 'Best First'.
Re^4: sh: -c: line 1: syntax error near unexpected token `|'
by Anonymous Monk on May 10, 2012 at 13:54 UTC

    Regarding quotes, the OP might find a module that provides shell escaping useful. Such as String::ShellQuote.

    printf is probably more surefire than echo there:

    printf "%s" "$cmd" | grep -e '----'

    But shelling out is very error-prone (as the OP discovered) and pretty vain when the code can be reproduced in Perl in a few lines.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969778]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2015-07-29 14:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls