Search code examples
bashuclinux

On microblaze uclinux: put IP address to variable


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}

Solution

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