testgetifaddr.sh: Always use the first IP addr from 'ip -4 addr'

Terminate the awk after getting the first interface name and IP address
from 'ip -4 addr' output.  Otherwise, the test fails if the interface
in question has multiple IP addresses, as the test program returns
the first address, while awk prints all.
This commit is contained in:
Michał Górny 2021-08-22 09:53:31 +02:00
parent 8c1e5f9500
commit 2087e14b8e
1 changed files with 2 additions and 2 deletions

View File

@ -12,8 +12,8 @@ case $OS in
*)
IP="`which ip`" || exit 1
EXTIF="`LC_ALL=C $IP -4 route | grep 'default' | sed -e 's/.*dev[[:space:]]*//' -e 's/[[:space:]].*//'`" || exit 1
EXTIF="`LC_ALL=C $IP -4 addr show $EXTIF | awk '/[0-9]+:/ { print $2 }' | cut -d ":" -f 1`"
EXTIP="`LC_ALL=C $IP -4 addr show $EXTIF | awk '/inet/ { print $2 }' | cut -d "/" -f 1`"
EXTIF="`LC_ALL=C $IP -4 addr show $EXTIF | awk '/[0-9]+:/ { print $2; exit 0 }' | cut -d ":" -f 1`"
EXTIP="`LC_ALL=C $IP -4 addr show $EXTIF | awk '/inet/ { print $2; exit 0 }' | cut -d "/" -f 1`"
;;
esac