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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

To read the value of a variable

Reply to Message Icon

Name: Nanda_Anu
Date: September 16, 2003 at 04:07:15 Pacific
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




Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: September 16, 2003 at 04:51:12 Pacific
Reply:

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.


0

Response Number 2
Name: Nanda_Anu
Date: September 16, 2003 at 05:19:36 Pacific
Reply:

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


0

Response Number 3
Name: WilliamRobertson
Date: September 16, 2003 at 10:41:13 Pacific
Reply:

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.


0

Response Number 4
Name: David Perry
Date: September 16, 2003 at 17:32:55 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: To read the value of a variable

how to identify the size of a file www.computing.net/answers/unix/how-to-identify-the-size-of-a-file-/7523.html

ksh - variable of a variable name? www.computing.net/answers/unix/ksh-variable-of-a-variable-name/6821.html

AWK(reading from a variable) www.computing.net/answers/unix/awkreading-from-a-variable/7113.html