Re: eval command help... (680 Views)
Reply
Honored Contributor
sekar sundaram
Posts: 615
Registered: ‎11-14-2008
Message 1 of 11 (716 Views)

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??

 

Honored Contributor
sekar sundaram
Posts: 615
Registered: ‎11-14-2008
Message 2 of 11 (711 Views)

Re: eval command help...

i got it....the $HEX_VARIABLE has a carriage return(enter key)...
any idea how to remove the "enter key" ???
Honored Contributor
sekar sundaram
Posts: 615
Registered: ‎11-14-2008
Message 3 of 11 (707 Views)

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.
Acclaimed Contributor
Dennis Handly
Posts: 25,290
Registered: ‎03-06-2006
Message 4 of 11 (705 Views)

Re: eval command help...

[ Edited ]

>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)

Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 5 of 11 (701 Views)

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...

Honored Contributor
sekar sundaram
Posts: 615
Registered: ‎11-14-2008
Message 6 of 11 (699 Views)

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???

Acclaimed Contributor
Dennis Handly
Posts: 25,290
Registered: ‎03-06-2006
Message 7 of 11 (690 Views)

Re: eval command help...

[ Edited ]

>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)

Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 8 of 11 (689 Views)

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...

Honored Contributor
sekar sundaram
Posts: 615
Registered: ‎11-14-2008
Message 9 of 11 (684 Views)

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?
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 10 of 11 (680 Views)

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...

Acclaimed Contributor
Dennis Handly
Posts: 25,290
Registered: ‎03-06-2006
Message 11 of 11 (680 Views)

Re: eval command help...

>for this situation, can't we use eval command?

 

Why?  If you want to do command substitution, $() (or the archaic ``), do command substitution, not eval.

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.