:: Re: [DNG] Wifi device names: was sy…
Kezdőlap
Delete this message
Reply to this message
Szerző: Steve Litt
Dátum:  
Címzett: dng
Tárgy: Re: [DNG] Wifi device names: was systemd is haunting me
On Sun, 31 Jan 2016 18:20:12 -0500
Steve Litt <slitt@???> wrote:

> Mine has an unintended bug that no matter how high the argument,
> it prints the "last" one, where as yours prints nothing if the
> argument is higher. I think my unintended bug might be considered
> beneficial, although even better would be that if it's too high to
> return the number of the last wifi device.


I wrote such a script, using Rainer's superior way to determine
$lineno and Rainer's tr -d:

===========================================
#!/bin/sh
lineno=${1:-1}

fn=`mktemp`

ip -o link | \
cut -d ' ' -f2 | \
grep ^w | \
tr -d : > $fn

maxdev=`wc -l $fn | cut -d ' ' -f 1`
if test $maxdev -lt $lineno; then
echo =max$maxdev
else
head $fn -n $lineno | \
tail -n 1
fi
rm $fn
===========================================

When there's no argument, it delivers the first wifi device. With an
argument greater than 0 and less than or equal to the number of wifi
devices, it delivers the wifi device corresponding to the number. When
the argument is a number higher than the number of wifi devices, it
returns a string in the firm of "=max3", if there are 3 wifi devices.
If there were only 2 wifi devices, it would have returned "=max2".

There are probably better ways to write this script, but I think the
way I have it here exhibits the behavior I'd like.

SteveT

Steve Litt
January 2016 featured book: Twenty Eight Tales of Troubleshooting
http://www.troubleshooters.com/28