Computing.Net > Forums > Unix > To read the value of a variable

To read the value of a variable

Reply to Message Icon

Original Message
Name: Nanda_Anu
Date: September 16, 2003 at 04:07:15 Pacific
Subject: To read the value of a variable
OS: Win 2k
CPU/Ram: P IV & 64kb
Comment:

Hi,
I am facing a serious problem.Please tell me what is my mistake?
My script goes like :
#!/bin/ksh
for file in send*.log
do
if[ -f ${file}]
then
grep "filename inside the file" ${file} >> temp
grep "process number" ${file} >> temp
assigning variable:
set pnum=cat temp|tail-1 temp #temp has both filename & process number
echo " $pnum " #has to display pnum from temp
main script:
set -v
ndmcli EOJ
select statistics pnumber=${pnum};#here above pnum value is not assigned. why this problem does it requires any conversion from file output to assign
EOJ

else
exit
fi
done

I need to execute the above statement very badly:
select statistics pnumber=${pnum};
if give value user input ,it assigns.
but as a file output,it doesn't assign

help me
tell me what wrong i did
thank u
nanda_anu



Report Offensive Message For Removal


Response Number 1
Name: David Perry
Date: September 16, 2003 at 04:51:12 Pacific
Subject: To read the value of a variable
Reply: (edit)

There's a good thought. If no one answers your homework question immediately, post it 10 or 15 more times under different names. Hope that works out for you.

BTW you don't need to check for the existence of a file you just got from the for command.


Report Offensive Follow Up For Removal

Response Number 2
Name: Nanda_Anu
Date: September 16, 2003 at 05:19:36 Pacific
Subject: To read the value of a variable
Reply: (edit)

Even after removing if statement also
my variable is not assigned inside the script

Try to give solution:
in order to assign the value of a variable
in the following
select statistics pnumber=<pnum>;
my pnum value should be ex:16244 from an another file


Report Offensive Follow Up For Removal

Response Number 3
Name: WilliamRobertson
Date: September 16, 2003 at 10:41:13 Pacific
Subject: To read the value of a variable
Reply: (edit)

You set a variable in ksh with

var=value

not

set var=value

To evaluate a command and retrieve its value, use

var=$(command...)

tail returns the last n lines of a file. "cat filename | tail" does the same thing but less efficiently and with more typing.


Report Offensive Follow Up For Removal

Response Number 4
Name: David Perry
Date: September 16, 2003 at 17:32:55 Pacific
Subject: To read the value of a variable
Reply: (edit)

Please post a sample of your data file. We will be able to provide you with a better answer.

for file in `find . -type f -name "send*.log" -exec grep -l pattern {} \; ` ; do
pnum=`process number' $file
done


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: To read the value of a variable

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software