LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-19-2011, 01:57 PM   #1
wf201626
LQ Newbie
 
Registered: Aug 2009
Posts: 10

Rep: Reputation: 0
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.
 
Old 07-19-2011, 03:16 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by wf201626 View Post
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.
 
Old 07-19-2011, 03:25 PM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,442

Rep: Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Blank Lines in a Perl Script fusion1275 Programming 5 05-04-2011 06:21 PM
invoking perl inside a ksh script cheltz Linux - Newbie 4 02-09-2011 10:54 PM
perl script get enviromnet varible LINES= for current session zerobane Programming 6 04-02-2009 05:23 PM
Perl Script to select common lines in two files. perluser59 Programming 12 05-26-2008 02:19 AM
NEED HELP IN comment lines PERL Perl script adam_blackice Programming 17 11-07-2007 08:01 AM


All times are GMT -5. The time now is 04:54 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration