The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing two variables into a shell script? Bashar Shell Programming and Scripting 2 05-15-2007 10:00 AM
passing variables to awk from ksh script rein Shell Programming and Scripting 3 08-11-2005 11:29 AM
Passing variables to sql from batch shell in linux rama71 Linux 2 06-28-2005 03:38 PM
Passing shell variables to awk program.. Vishnu Shell Programming and Scripting 1 07-17-2004 10:04 AM
Passing variables from one script to another tcoventr UNIX for Dummies Questions & Answers 2 06-18-2002 10:57 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 01-15-2008
Xek Xek is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 1
Need help passing variables in shell script to perl one-liner

I'm writing a script to automate some post-install tasks on RHEL4 servers.
I need the following code to insert an 'A' in the middle of a string, then replace the string in a file. I know I can use sed to do this, but I'd like to use perl's in place edit so I don't have to write to a temp file, then overwrite the original.

Here's what I have so far:

mystr1=`grep Mlocal submit.cf | cut -d, -f3` #grab the string
mystr2=`echo $mystr1 | awk '{print substr($1,1,7) "A" substr($1,8)}'` #insert the 'A'
perl -i -p -e 's/$mystr1/$mystr2/' submit.cf #search and replace

The variables (mystr1 and mystr2) are not importing into the perl statement. I've tried exporting them with 'typeset -x' and using:

perl -i -p -e 's/$ENV{"mystr1"}/$ENV{"mystr2"}/' submit.cf #search and replace

Which works with:
perl -e 'print $ENV{"mystr2"}'
but not with search and replace

I know the search and replace syntax is correct because the following section of my script to uncomment the alias file works fine:

if [ `grep AliasFile submit.cf | cut -c1` = "#" ]
then
perl -i -p -e "s/#O AliasFile/O AliasFile/" submit.cf
fi



Any help is greatly appreciated.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0