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
Reading file and assigning that to Variable Vaddadi Shell Programming and Scripting 2 04-03-2008 02:49 PM
reading a line into a variable in unix lmadhuri UNIX for Dummies Questions & Answers 1 02-07-2007 10:04 AM
perl - file reading - last line not displayed matrixmadhan UNIX for Dummies Questions & Answers 8 12-18-2006 02:10 PM
Perl Reading from File karyn1617 Shell Programming and Scripting 1 02-17-2005 08:44 PM
Reading input to create a variable in a script? darthur UNIX for Dummies Questions & Answers 7 12-14-2001 01:12 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-24-2007
yoonixq4u yoonixq4u is offline
Registered User
  
 

Join Date: Aug 2007
Location: Sacramento, CA
Posts: 4
perl not reading my variable

I'm trying to make changes in a file using the following bash script:

Code:
#!/bin/bash

MYHOME=`echo $HOME`
README=$MYHOME"/environment"
IAM=`whoami`

CHANGEPATHLIST="TALOG TACONFIG TAINFO TAWORK TMPSPACE"

for var in $CHANGEPATHLIST
do
   perl -pi -e 's/sacuser1/$IAM/ if m/$var/' $README
done
The problem is $var and $IAM are interpreted as null. If I echo the values of these variables, I can see that they are correct.
So I guess my question is am I not allowed to use variables in the above perl command?

TIA,
Jennifer
  #2 (permalink)  
Old 08-24-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
I'm not sure what you are trying to do, things seem out of place - but
Code:
perl -pi -e "s/sacuser1/$IAM/ if m/$var/" $README
Change the single quotes to double quotes.
Plus ~ is translated to $HOME - try that instead of the MYHOME thing.
  #3 (permalink)  
Old 08-24-2007
yoonixq4u yoonixq4u is offline
Registered User
  
 

Join Date: Aug 2007
Location: Sacramento, CA
Posts: 4
Thank you thank you thank you!
The double quotes did the trick. But why? Are the vars interpreted differently when I use double quotes?
  #4 (permalink)  
Old 08-24-2007
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
Otherwise '$var' and '$IAM' are passed as is to Perl, rather than the values expanded by the shell.
Closed Thread

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 08:22 PM.


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