Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Eval function

Status
Not open for further replies.

conquersmile

Technical User
Aug 29, 2003
20
AU
Hello,

Can anybody help me with eval function in unix, I have no idea about it and i want some help.

Regards,
Padma Swamy
 
Hi Padma, what's worrying in "eval"? I use "eval" sometimes because it's a little tricky.
The standard definition of eval is:
"The eval command can be used when you want the shell to reprocess the command line a second time."
I.E.
The following function converts a number from Decimale to Hexadecimal and puts the result in a variable which name is passed as an argument:
#
# Dec2Hex :
# Converts the number in $1 (0 - 255) to hex 2 digits notation and puts it in the var specified in $2
#
Dec2Hex () {
stringa=$1
conv="0123456789ABCDEF"
a=`expr $stringa / 16`
b=`expr $a \* 16`
if [ $a -eq 0 ];then
digit1="0"
posiz=`expr $stringa + 1`
digit2=`echo $conv|cut -c$posiz`
eval ${2}=$digit1$digit2;
return
fi
posiz=`expr $a + 1`
digit1=`echo $conv|cut -c$posiz`
if [ $b = $stringa ];then
digit2="0"
else
posiz=`expr $stringa - $b`
posiz=`expr $posiz + 1`
digit2=`echo $conv|cut -c$posiz`
fi
eval ${2}="$digit1$digit2";
return
}

Hope to be useful
 
Hi,

I am using it to assign a value to a variable, which is generated dyanmically.

Regards,
Padma Swamy
 
Well .. it should differ just a little from the use I did.
A little question for you:
I find the name Padma for the 1st time in Harry Potter :))
Where you from?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top