Date:        Mon, 17 Nov 2025 22:53:14 -0800
    From:        "Greg A. Woods" <[email protected]>
    Message-ID:  <[email protected]>

You do know that you could do this:

  | +                   for ip6addr in $(/sbin/ifconfig $int |
  | +                                   while read word arg stuff
  | +                                   do
  | +                                           case $word in
  | +                                           inet6)
  | +                                                   printf '%s\n' "${arg}"
  | +                                                   ;;
  | +                                           esac
  | +                                   done
  | +                           )
  | +                   do
  | +                           /sbin/ifconfig $int inet6 delete "$ip6addr"
  | +                   done

more simply, just as:

        /sbin/ifconfig "$int" |
                while read word arg stuff
                do
                        case $word in
                        inet6)
                                

                                ;;
                        esca
                done

?   In some situations that might be doubtful, as you'd be changing what
output the initial ifconfig is generating, while it is is still producing
it (nominally anyway) - but ifconfig doesn't work like that, it will have
obtained the complete info for the interface, before it starts writing
anything, so later changes will have no effect.

The form using the command substitution extracts all of the v6 addresses
from the ifconfig output, and adds them as words for the for loop, before
that loop starts running, so would be, in other cases, safer.

Do quote expansions, almost always - most people would also
quote the $word - but that is one situation where it isn't really
needed - another is in assignments, like X=$word

I didn't bother with all that previously, as my only real intent that
time was to get rid of the use of awk.

kre

ps: it is also stated in ifconfig(8)

        delete does not work for IPv6 addresses.
        Use -alias with explicit IPv6 address instead.

That is, the

        /sbin/ifconfig "$int" inet6 delete "$arg"

should probably be written as

        /sbin/ifconfig "$int" inet6 "$arg" -alias

just to be safer - though personally I doubt that almost anyone
truly understands how the ifconfig code actually works - I certainly
don't, it is all just black magic.


Reply via email to