获取网卡IP地址
在脚本中经常会需要获得 eth0 的IP地址,以下是获取案例:
#!/bin/bash
ifconfig eth0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1命令行:
ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1脚本:
#!/bin/bash
theIPaddress=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)参考
Last updated
Was this helpful?