需求
shell脚本里我需要根据不同的ip地址做出不同的操作,因此我需要在shell脚本里获取当前主机的ip地址
![](https://img-my.csdn.net/uploads/201302/01/1359719313_9666.png)
我需要获取到192.168.1.111这个ip地址
方法1
ifconfig |grep 'inet 地址'|grep '192.168.1' | grep -v 'grep' | awk '{print $2}'| tr -d "地址:"
效果
![](https://img-my.csdn.net/uploads/201302/01/1359719405_8845.png)
ifconfig |grep 'inet 地址'|grep '192.168.1' | grep -v 'grep' | awk '{print $2}'| tr -d "地址:"