简体   繁体   English

获取linux shell脚本变量的接口名称

[英]Get interface name into linux shell script variable

I would like to store an interface name into a variable in linux shell script. 我想将接口名称存储在linux shell脚本中的变量中。 I found a solution to do this via "grep" command and the IP-Address. 我通过“grep”命令和IP地址找到了解决方案。 My problem is that my interface doesn't have an IP-Address at this moment. 我的问题是我的界面此刻没有IP地址。

The interface name always begins with "enx" and the MAC-Address like "enxb2240be99fc3" while the MAC-Address can change every reboot. 接口名称始终以“enx”开头,MAC-Address始终以“enxb2240be99fc3”开头,而MAC-Address可以在每次重新启动时更改。

Is there a solution to get this interface name into a shell script variable? 有没有解决方案将此接口名称转换为shell脚本变量?

iname=$(ip -o link show | sed -rn '/^[0-9]+: en/{s/.: ([^:]*):.*/\1/p}')

将接口名称保存到变量iname

ip addr show | ip addr show | awk '/inet.*brd/{print $NF}' awk'/inet.*brd / {print $ NF}'

this is also works,check it... 这也有效,检查一下......

iname=$(ls /sys/class/net | grep -i enx)
echo $iname

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM