On Fri 23 Apr 2021 at 23:11:58 (-0400), Greg Wooledge wrote: > On Fri, Apr 23, 2021 at 09:59:09PM -0500, David Wright wrote: > > OTOH my startup files set Mywiredifname for scripts to use, where: > > > > Mywiredifname=$(ip -o link show | sed -e '/^[0-9]\+: [^e]/d;s/[0-9]\+: > > \([^:]\+\): .*/\1/;q') > > > > $ echo $Mywiredifname > > enp3s0 > > unicorn:~$ ip -o link show | awk -F': ' '{print $2}' > lo > lan0
Yes —— though one might wonder why someone would use this little script to discover the interface name on a system where, I assume, they chose the name themselves. > You're relying on the "default" names which ensure that an ethernet > interface begins with an 'e', so we could fold that in as well: > > ip -o link show | awk -F': ' '$2 ~ /^e/ {print $2}' One certainly has to eliminate 'w', at the very least, to eliminate any wireless card. And {print $2; exit} guarantees only one match, to correspond with my 'q'. > It's slightly prettier than yours, and doesn't rely on GNUisms (which are > probably not a big issue since a system with "ip" probably has GNU sed). > > > (My days of running multiple ethernet cards are long gone, > > so sed will quit after one match.) > > Sounds like a naive assumption. Some motherboards have dual NICs built in, > don't they? I look forward to the day. I've got this far in life without ever buying a computer, so I may well never see one. It /is/ an assumption, hence my mentioning it. I don't want to overpromise—the substance of my post was contained in 5 keystrokes: ip a for Cindy to type, instead of greping kern.log and dmesg. My assumption that all modern PCs would have one ethernet interface has already fallen by the wayside—some (most?) laptops now have zero. But thanks for the awk suggestions. All the (trivial) awk code in my startup files is just copied from elsewhere. I think the reason I never got into awk is simply that I came from mainframes/spitbol via MSDOS/perl/grep/sed to linux/python. Cheers, David.