Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get interface name into linux shell script variable

Tags:

linux

shell

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?

like image 766
D.W. Avatar asked Sep 25 '26 06:09

D.W.


1 Answers

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

save the interface name to variable iname

like image 113
jijinp Avatar answered Sep 26 '26 21:09

jijinp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!