LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problems with grep when used with echo (https://www.linuxquestions.org/questions/linux-newbie-8/problems-with-grep-when-used-with-echo-628966/)

pavan_pnv 03-18-2008 12:26 PM

Problems with grep when used with echo
 
I am trying to run the below lines from within a perl script:
my $temp=`echo "DISPLAY QMGR DEADQ SCMDSERV SCHINIT" | runmqsc`;
print `$temp | egrep "QMGR|SCH"`;

But, I get an error saying:
sh: syntax error at line 1: `5724-H72' unexpected

The output when we run the above command from ksh will be:
bash-2.03$ echo "DISPLAY QMGR DEADQ SCMDSERV SCHINIT" | runmqsc
5724-H72 (C) Copyright IBM Corp. 1994, 2005. ALL RIGHTS RESERVED.
Starting MQSC for queue manager NIMESU02.


1 : DISPLAY QMGR DEADQ SCMDSERV SCHINIT
AMQ8408: Display Queue Manager details.
QMNAME(NIMESU02) DEADQ(DEAD.LETTER.QUEUE)
SCHINIT(QMGR) SCMDSERV(MANUAL)
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.


Thanks for helping me!

cmnorton 03-18-2008 02:50 PM

confusion
 
How is the print command causing a shell script to run? I'm a little rusty with Perl.

prad77 03-18-2008 04:28 PM

You have to shuffle up between single, double and back quotes. I am not sure which set goes with shell scripting and which ones with perl. But it will go well handy with proper set of quotes.

Fedora Development

chrism01 03-18-2008 06:28 PM

You could change this
print `$temp | egrep "QMGR|SCH"`;
to
`echo $temp | egrep "QMGR|SCH"`;
if I follow you correctly.


All times are GMT -5. The time now is 03:05 AM.