perl not reading my variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl not reading my variable
# 1  
Old 08-24-2007
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  
Old 08-24-2007
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  
Old 08-24-2007
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  
Old 08-24-2007
Otherwise '$var' and '$IAM' are passed as is to Perl, rather than the values expanded by the shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl : reading data from dumper variable

Hi team, # PERL I have Dumper variable in perl and containing the below data and trying to fetch value and name from the reference variable. $VAR1 = { 'retainSysIds' => 'true', 'variables' => , 'name' => , ... (4 Replies)
Discussion started by: giridhar276
4 Replies

2. Shell Programming and Scripting

Error while reading variable from a file in perl script

I have a file abc.ini and declared many variables in that file, one of the variable(DBname) value I am trying to read in my perl script but getting error. File abc.ini content # database name DBname =UATBOX my $ex_stat; my $cmd_output; $ex_stat = "\Qawk '/^DBname/{print... (2 Replies)
Discussion started by: Devesh5683
2 Replies

3. Shell Programming and Scripting

Perl :: reading values from Data Dumper reference in Perl

Hi all, I have written a perl code and stored the data into Data structure using Data::Dumper module. But not sure how to retreive the data from the Data::Dumper. Eg. Based on the key value( Here CRYPTO-6-IKMP_MODE_FAILURE I should be able to access the internal hash elements(keys) ... (1 Reply)
Discussion started by: scriptscript
1 Replies

4. Shell Programming and Scripting

Reading a variable in csh

I have a simple script that sets a value and reads the value in csh: set -x set a = 10 echo $a The output of the script does not show the value of a + set a = 10 + echo any help would be great. (4 Replies)
Discussion started by: pt14
4 Replies

5. Shell Programming and Scripting

reading variable value from a file

Hello, I need to read a variable value from script. Below is the scenario I am reading a value from an external file say a.txt a.txt: Jan Feb Mar I need the corresponding value of the months in in numerics such as Jan -->1, Feb-->2 etc. I have this mapping in another file... (1 Reply)
Discussion started by: aixjadoo
1 Replies

6. UNIX for Dummies Questions & Answers

Reading a variable from file

Hi, I have a situation where I need to read a variable from another file. But the problem is that the variable in the other file is starting with $. E.g. file1: $var1=out temp_ss.sh: . file1 echo "Print : $var1" It works fine if the file1 is having var1=out (note that it is... (6 Replies)
Discussion started by: shash
6 Replies

7. Shell Programming and Scripting

Reading variable from file variable values

Hi, Here is the output of lpstat. I would like to read value of Queue which is(abxxxxb1)and status that is DOWN in first line. i dont care what is in second line. any one can help me.thanks Queue Dev Status Job Files User PP % Blks Cp Rnk ------- ----- ---------... (5 Replies)
Discussion started by: sagii
5 Replies

8. UNIX for Dummies Questions & Answers

reading more than one variable into a for loop

Hi, I have a file (details.txt) with 3 rows of variables ie... name postcode age john D fr25dd 25 mark W ab122aa 22 phil C cd343bb 33 What I want to do is read down the list with a loop and add each field into a one line piece of text... So I have a file (test1) which reads;... (3 Replies)
Discussion started by: starsky
3 Replies

9. Shell Programming and Scripting

reading ~/.bashrc variable

1) I've added a variable called IMPORT_HOME to my ~/.bashrc file: IMPORT_HOME=/import:$IMPORT_HOME 2) I sourced the bashrc file: source ~/.bashrc 3) In my bash script, i tried to echo out the IMPORT_HOME variable but it doesnt print out '/import/, only whitespace: #!/bin/bash echo... (2 Replies)
Discussion started by: nuGz
2 Replies

10. UNIX for Advanced & Expert Users

Urgent-reading a variable value

Hi, I have a text file in which , I have contents like t1=abc t2=xyz t3=awe ...... I am able to read contents of these variables in a script by . /temp.txt echo $t1 Now, what my requirement is something like this a="t" i=1 echo $a$i --->this is displaying t1 (3 Replies)
Discussion started by: kaaakrishna
3 Replies
Login or Register to Ask a Question