On microblaze uclinux: put IP address to variable

77 Views Asked by At

Yes, this is related to Putting IP Address into bash variable. Is there a better way but nothing of the ideas there work for me on the microblaze uclinux. I wish to have my ip address of eth0 stored to a shell variable that I can write a script using it. I need alternative ideas how to do this.
ifconfig is available if that helps. I found that in the file /etc/config/dhcp0.conf the correct ip address is stored, here's the file's content:

1 192.168.10.102

How can I remove the 1 and space without using following commands

  • grep
  • sed
  • cut
  • this also does not work: echo ${variable:2}
2

There are 2 best solutions below

0
Barmar On BEST ANSWER

You can use the shell's read built-in:

read num ip </etc/config/dhcp0.conf

$num will contain the number at the beginning of the line, $ip will contain the IP.

3
jracine On

Assign ifconfig output of eth0 to array

ifout=($(ifconfig eth0))

Strip off everything before the semicolon of the 6th element of array and assign it to the variable $ethip

ethip=${ifout[6]#*:}