:: Re: [DNG] Wifi device names: was sy…
Forside
Slet denne besked
Besvar denne besked
Skribent: Rainer Weikusat
Dato:  
Til: dng
Emne: Re: [DNG] Wifi device names: was systemd is haunting me
Steve Litt <slitt@???> writes:
> On Sun, 31 Jan 2016 18:20:12 -0500
> Steve Litt <slitt@???> wrote:


[...]

> ===========================================
> #!/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
> ===========================================


[...]

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


'Better' is often very much a matter of opinion but here's one which
doesn't need a temporary file:

---------
#!/bin/sh
want=${1:-1}
got=0

for dev in `ip -o link | sed -n 's/[^:]*: *\(w[^:]*\).*/\1/p'`;
do
    got=`expr $got + 1`


    test $got -eq $want && {
    echo $dev
    exit 0
    }
done


echo =max$got
--------