linux shell echo GUESS_IPV4_IF=$(ip route show | grep default | head -1 | sed -r 's/.+dev ([^ ]+echoGUESS_IPV4_IF=$(ip route show | grep default | head -1 | sed -r 's/.+dev ([^ ]+) .+/\1/')GUESS_PRIMARY_IPV4=$(ip addr show primary | grep "inet " | aw

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/22 23:01:19
linuxshellechoGUESS_IPV4_IF=$(iprouteshow|grepdefault|head-1|sed-r''s/.+dev([^]+echoGUESS_IPV4_IF=$(i

linux shell echo GUESS_IPV4_IF=$(ip route show | grep default | head -1 | sed -r 's/.+dev ([^ ]+echoGUESS_IPV4_IF=$(ip route show | grep default | head -1 | sed -r 's/.+dev ([^ ]+) .+/\1/')GUESS_PRIMARY_IPV4=$(ip addr show primary | grep "inet " | aw
linux shell echo GUESS_IPV4_IF=$(ip route show | grep default | head -1 | sed -r 's/.+dev ([^ ]+
echo
GUESS_IPV4_IF=$(ip route show | grep default | head -1 | sed -r 's/.+dev ([^ ]+) .+/\1/')
GUESS_PRIMARY_IPV4=$(ip addr show primary | grep "inet " | awk '{print $2}' | sed -r 's/\/[0-9]+$//' | tail -1)

linux shell echo GUESS_IPV4_IF=$(ip route show | grep default | head -1 | sed -r 's/.+dev ([^ ]+echoGUESS_IPV4_IF=$(ip route show | grep default | head -1 | sed -r 's/.+dev ([^ ]+) .+/\1/')GUESS_PRIMARY_IPV4=$(ip addr show primary | grep "inet " | aw
1) echo 输出一个空行
2) GUESS_IPV4_IF=$(ip route show | grep default | head -1 | sed -r 's/.+dev ([^ ]+) .+/\1/')
将本机默认网关 和 网卡赋值给GUESS_IPV4_IF变量(例如:default via 192.168.2.1 dev eth0 默认网关为192.168.2.1 网卡为 eth0)
3) GUESS_PRIMARY_IPV4=$(ip addr show primary | grep "inet " | awk '{print $2}' | sed -r 's/\/[0-9]+$//' | tail -1) 将本机的ip地址赋值给GUESS_PRIMARY_IPV4变量(例如:192.168.2.92)