1748138 Members
3726 Online
108758 Solutions
New Discussion

Re: eval command help...

 
sekar sundaram
Honored Contributor

eval command help...

/opt/OV/bin/OpC/install/opc_ip_addr -help

Usage: opc_ip_addr [hostname] .. [hostname]
opc_ip_addr [ip] .. [ip]
opc_ip_addr -r [hexip] .. [hexip]
Convert an hostnames or an ip-adresses to a hex-ip-strings w/o dots

 

i want to convert a hexip to node name.

that is 

opc_ip_addr -r hexip

 

when i run straight forward:

sekar@OVO> /opt/OV/bin/OpC/install/opc_ip_addr -r <hexip>

node.name.com    = 1.1.2.3 = <hexip>

 

but thru a script, i will have the hexip thru a variable.

inside the script, when i run

/opt/OV/bin/OpC/install/opc_ip_addr -r $HEXIP_VARIABLE
its not using the value of HEXIP_VARIABLE. it says "no hex_ip or  wrong format"

 

any clues?? you need more infromation??

 

10 REPLIES 10
sekar sundaram
Honored Contributor

Re: eval command help...

i got it....the $HEX_VARIABLE has a carriage return(enter key)...
any idea how to remove the "enter key" ???
sekar sundaram
Honored Contributor

Re: eval command help...

assume the value of ID is f375e6da-b5e7-71a0-0235-031f8e1e0000

now
hexvalue=cut -c26-32 $ID

this returns "-c26-32 not found

hexvalue=`cut -c26-32 $ID`
this returns
cut: Cannot open f375e6da-b5e7-71a0-0235-031f8e1e0000.
Dennis Handly
Acclaimed Contributor

Re: eval command help...

>any idea how to remove the CR?

 

You fix your data file so it doesn't end in CR/LF with dos2ux(1).

Or you would remove the last char of the variable:

HEX_VARIABLE=${HEX_VARIABLE%.}

 

Or use echo and tr(1) to delete it.

Or use echo and cut(1) to remove it:

hexvalue=$(echo $ID | cut -c26-32)

James R. Ferguson
Acclaimed Contributor

Re: eval command help...

Hi:


@sekar sundaram wrote:
i got it....the $HEX_VARIABLE has a carriage return(enter key)...
any idea how to remove the "enter key" ???

You could do:

 

HEX_VARIABLE=$(echo ${HEX_VARIABLE}|perl -pe 's/\r//g')

or even faster:

 

HEX_VARIABLE=$(echo ${HEX_VARIABLE}|tr -d "\015")

Regards!

 

...JRF...

sekar sundaram
Honored Contributor

Re: eval command help...

Cool....its good...

HEX_IP=$(echo $ID | cut -c26-32)

 

one more issue....

 

when i run 

opc_ip_addr -r $HEX_IP

it runs good...

 

but when i assign the value to NODE like this,

NODE=opc_ip_addr -r $HEX_IP

it gives:

./script.sh: -r:  not found

 

any ideas???

Dennis Handly
Acclaimed Contributor

Re: eval command help...

>but when I assign the value to NODE like this: NODE=opc_ip_addr -r $HEX_IP

 

The correct form for command substitution is:

NODE=$(opc_ip_addr -r $HEX_IP)

 

>./script.sh: -r:  not found

 

Your syntax did something like: (export NODE=opc_ip_addr; -r $HEX_IP)

James R. Ferguson
Acclaimed Contributor

Re: eval command help...


@sekar sundaram wrote:

Cool....its good...

HEX_IP=$(echo $ID | cut -c26-32)

 

one more issue....

 

when i run 

opc_ip_addr -r $HEX_IP

it runs good...

 

but when i assign the value to NODE like this,

NODE=opc_ip_addr -r $HEX_IP

it gives:

./script.sh: -r:  not found

 

any ideas???


Hi:

 

Of course.  Do:

 

NODE=$(opc_ip_addr -r $HEX_IP)

 

By the way, using 'cut' with columns means that this only works if your input string has exactly the format you want.  I'd use the 'tr' I suggested above.

 

Regards!

 

...JRF...

sekar sundaram
Honored Contributor

Re: eval command help...

super cool....i got it 100%...

between,
NODE=opc_ip_addr -r $HEX_IP
for this situation, cant we use eval command?
James R. Ferguson
Acclaimed Contributor

Re: eval command help...


@sekar sundaram wrote:
super cool....i got it 100%...

between,
NODE=opc_ip_addr -r $HEX_IP
for this situation, cant we use eval command?

Why?  The $(...) for is the modern replacement for the archaic backtick syntax.  This runs the command and assigns the output (if any) to the lvalue (variable).

 

An 'eval' is used in situations where you need the shell to scan input twice; once to interpolate variables and the second time to use them.

 

Regards!

 

...JRF...