I would like to store an interface name into a variable in linux shell script. I found a solution to do this via "grep" command and the IP-Address. My problem is that my interface doesn't have an IP-Address at this moment.
The interface name always begins with "enx" and the MAC-Address like "enxb2240be99fc3" while the MAC-Address can change every reboot.
Is there a solution to get this interface name into a shell script variable?
iname=$(ip -o link show | sed -rn '/^[0-9]+: en/{s/.: ([^:]*):.*/\1/p}')
save the interface name to variable iname
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With