LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   perl one-lines within a ksh script in aix environment not excute (http://www.linuxquestions.org/questions/programming-9/perl-one-lines-within-a-ksh-script-in-aix-environment-not-excute-892561/)

wf201626 07-19-2011 02:57 PM

perl one-lines within a ksh script in aix environment not excute
 
hi all

I have a script to utilize the perl one liner to replace a ip address.

Code:

#!/usr/bin/ksh
set -x
PRIP=172.15.100.176
OPRIP=172.15.100.115
PNAME=oqhismfp
sub="s/${PRIP}/${OPRIP}/"
sub1=" if /\b"
sub2="${PNAME}"
sub3="\b/"
/usr/bin/perl -piw -e "'${sub}${sub1}${sub2}${sub3}'" /etc/hosts

the script runs fine. but the perl one liner seems not working at all. but if i copy the perl line to a command line, it runs correctly.

i am not a perl expert, only use it occasionally.

any one has an idea why it does not run as expect.

thanks in advance,

F.

Sergei Steshenko 07-19-2011 04:16 PM

Quote:

Originally Posted by wf201626 (Post 4419303)
hi all

I have a script to utilize the perl one liner to replace a ip address.

Code:

#!/usr/bin/ksh
set -x
PRIP=172.15.100.176
OPRIP=172.15.100.115
PNAME=oqhismfp
sub="s/${PRIP}/${OPRIP}/"
sub1=" if /\b"
sub2="${PNAME}"
sub3="\b/"
/usr/bin/perl -piw -e "'${sub}${sub1}${sub2}${sub3}'" /etc/hosts

the script runs fine. but the perl one liner seems not working at all. but if i copy the perl line to a command line, it runs correctly.

i am not a perl expert, only use it occasionally.

any one has an idea why it does not run as expect.

thanks in advance,

F.

I don't understand why it's written this way. Why do you need the 'ksh' script in the first place ? Why have you introduced all these 'sub*' variables ?

Anyway, if one-liner doesn't work, make it a non-one-liner and debug the usual way.

grail 07-19-2011 04:25 PM

I am with Sergei ... unless this is a snippet of a much larger script (even then maybe should all be perl), I see no reason to split this between languages.

You say that the perl one liner part works fine at the command line? Please confirm that this means you have set the same variables within the shell and executed the one liner
the same way?


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