Method Two
/sbin/ifconfig-a|grep inet|grep-v 127.0.0.1|grep-v Inet6|awk ' {print $} ' |tr-d ' addr: '
Method One
Get the native IP address and save it in a variable
arg=ifconfig eth0 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "
Ipaddr= < Span class= "Mrow" id= "mathjax-span-200" > a r g e c h o Ipadd
This assumes that your interface name is eth0, it is possible that your interface is not this, you need to change it.
Introduction to cut Parameters
-D is used to define the delimiter, which defaults to the TAB key.
-F indicates which field to get, 2 means the second field to be split with the delimiter specified by-D
Of course, you can also get a specific number of characters in each line of the file by cut, for example:
Cut-c3-5/etc/passwd
is the third to fifth character of each line in the output/etc/passwd file.
The-C and-f parameters can be followed by the following sub-parameters:
n Nth character or field
N-from the first character or field to the end of the file
N-m from Nth to first M characters or fields
-m character or field from first to second
Linux under the shell to get the native IP address