Weird Variable Evaluation problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Weird Variable Evaluation problem
# 1  
Old 09-02-2008
Network Weird Variable Evaluation problem

Hi Guys..

I have a script which is:

#!/bin/ksh
for file in `grep qtc $PIC_SHS/xback00.ksh |cut -d"=" -f2`
do
ls $file
cp $file ./
done


output of grep is
$ grep qtc $PIC_SHS/xback00.ksh |cut -d"=" -f2
$PIC_BIN/XPBACKRC0.qtc
$PIC_BIN/XPBACK000.qtc
$PIC_BIN/XPBACKSS0.qtc
$PIC_BIN/XPBACKSP0.qtc
$PIC_BIN/XPBACKAL0.qtc
$PIC_BIN/XPBACKBO0.qtc
$PIC_BIN/XPBACKTC0.qtc
$PIC_BIN/XPBACKFC0.qtc

$PIC_BIN is a environment variable.

$ ls -l $PIC_BIN/XPBACKRC0.qtc
-rwxrwxrwx 1 ddshupmg gmwms 8448 Feb 7 2007 /disk1/uketddshup/common/bin/XPBACKRC0.qtc

the files exist.. but when give the grep output as input list to for loop, it doesnt evaluate it.. and gives an error like :
$ ./copy.ksh
$PIC_BIN/XPBACKRC0.qtc: No such file or directory
cp: cannot access $PIC_BIN/XPBACKRC0.qtc
$PIC_BIN/XPBACK000.qtc: No such file or directory
cp: cannot access $PIC_BIN/XPBACK000.qtc
$PIC_BIN/XPBACKSS0.qtc: No such file or directory
cp: cannot access $PIC_BIN/XPBACKSS0.qtc
$PIC_BIN/XPBACKSP0.qtc: No such file or directory
cp: cannot access $PIC_BIN/XPBACKSP0.qtc
$PIC_BIN/XPBACKAL0.qtc: No such file or directory
cp: cannot access $PIC_BIN/XPBACKAL0.qtc
$PIC_BIN/XPBACKBO0.qtc: No such file or directory
cp: cannot access $PIC_BIN/XPBACKBO0.qtc
$PIC_BIN/XPBACKTC0.qtc: No such file or directory
cp: cannot access $PIC_BIN/XPBACKTC0.qtc
$PIC_BIN/XPBACKFC0.qtc: No such file or directory
cp: cannot access $PIC_BIN/XPBACKFC0.qtc


Any idea how to evaluate the variable in for loop.. at shell level it works.. Smilie
# 2  
Old 09-02-2008
You can use eval, or if you have just one variable you want to replace, do a substitution with sed.

Code:
grep qtc $PIC_SHS/xback00.ksh |cut -d"=" -f2 | sed 's%\$PIC_BIN%'"$PIC_BIN"%

# 3  
Old 09-02-2008
yay!

Smilie awesome dude.. thanks .. it works!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Weird awk problem

Hi, I have a simple awk script: BEGIN{} { $a=$2-$1; print $a } END{if(NR==0){ print "0" } } to which I provide the following input 2.9 14 22.2 27 (4 Replies)
Discussion started by: jamie_123
4 Replies

2. UNIX for Dummies Questions & Answers

Weird problem with join command

I have a weird issue going on with the join command... I have two files I am trying to join...here is a line from each file with the important parts marked in red: file1: /groupspace/ccops/cmis/bauwkrcn/commsamp_20140315.txt,1 file2:... (3 Replies)
Discussion started by: dbiggied
3 Replies

3. Shell Programming and Scripting

weird equal variable issue

I run this #!/bin/bash cron=$(ps aux | grep crond | grep -v grep | grep -o crond| uniq) echo "cron :$cron:" if ; then echo "OK: crond service running fine on `hostname`" exit 2 else echo "CRITICAL: crond service not running on `hostname`" exit 0... (2 Replies)
Discussion started by: anil510
2 Replies

4. Shell Programming and Scripting

awk weird problem.

awk 'BEGIN{print 1.2.3.4}' 1.20.30.4 Can anyone explain why has extra "0" in the IP address? (3 Replies)
Discussion started by: newoz
3 Replies

5. Infrastructure Monitoring

Weird dependency problem!

Hi, I want to install net-snmp-devel package but i have following dependecy problem. It's very odd, i don't get it. One of packages is depended on the other one, the other one is depended on the previous one as well. :S :S Could you help me please? Here are the steps: # ls -l total... (4 Replies)
Discussion started by: oduth
4 Replies

6. UNIX for Advanced & Expert Users

Really weird delete problem

Hi, I've Ubuntu 8.04, and it has some files that I just cannot delete. I've tried everything, inode, fsck etc. Here is what the ls -li outputs root@ubuntu:/home/luser/.local/share/Trash/files/junk# ls -l ls: cannot access TRUNK_: No such file or directory ls: cannot access 2006_output.mv:... (11 Replies)
Discussion started by: nitin
11 Replies

7. AIX

weird file list problem

When I do a file list in my spooler directory, I get the following information #ls -l |pg -rw-rw-rw- 1 user1 ugroups 831690 Apr 03 12:52 K6A80403125051.prn :res 2330479869879093344 ext 2330477052380546512 align -rw-rw-rw- 1 user1 ugroups 5900 Apr 03 14:19 K6A80403141858.idx :res... (8 Replies)
Discussion started by: jmmora
8 Replies

8. Shell Programming and Scripting

Weird date difference problem

I am trying to find the difference in days between 2 dates. I have to extract the 1st date from a filename, which i did using the awk command. I have to compare this date to today's date and if the difference is greater than 30 days, do something, else do something else. This is what i wrote... (22 Replies)
Discussion started by: meeraKh
22 Replies

9. Solaris

Weird crontab problem

Greetings To All! I am running Solaris 10 in a sparc environment. Here is the deal: In /var/spool/cron/crontabs, there is a cron user named "sys". If I do a crontab -l sys, it returns: # 0 * * * 0-6 /usr/lib/sa/sa1 # 20,40 8-17 * * 1-5 /usr/lib/sa/sa1 # 5 18 * * 1-5 /usr/lib/sa/sa2... (8 Replies)
Discussion started by: RobSand
8 Replies

10. UNIX for Dummies Questions & Answers

Weird Problem???

I have a problem I don't understand... I am trying to declare a variable, and then output the results of that variable, couldn't be simpler #!/bin/ksh VAR='Oranges' if then echo "Found Lemons" elif then echo "Found Oranges" fi The output shouold clearly be "Found Oranges", but... (2 Replies)
Discussion started by: danhodges99
2 Replies
Login or Register to Ask a Question