With this patch, v[46]_info() both output exactly what their description
says.
As of now, these functions are only used through
set -- $(v4_info $_if)
which gracefully handles any constellation of whitespaces in the output
just fine. However future usage might change (or not) and being precise
about a function's output doesn't hurt.
The sed command itself is a tad clearer/smarter that way as well, imho.
Here's what I mean (whitespaces visualised):
$ v4_info trunk0
UP
› ·192.168.1.2··0xffffff00·broadcast·192.168.1.255
$ v4_info_clean trunk0
UP
192.168.1.2·0xffffff00·broadcast·192.168.1.255
Feeback/OK?
Index: install.sub
===================================================================
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1014
diff -u -p -r1.1014 install.sub
--- install.sub 3 Jun 2017 22:27:41 -0000 1.1014
+++ install.sub 14 Jun 2017 15:13:05 -0000
@@ -896,13 +896,14 @@ __EOT
}
# Obtain and output the inet information related to interface $1.
-# Should output '<UP/DOWN> <addr> <netmask> <rest of inet line>'.
+# Outputs '<UP/DOWN>\n<addr> <netmask> <rest of inet line>'.
v4_info() {
ifconfig $1 inet | sed -n '
- 1s/.*<UP,.*/UP/p
- 1s/.*<.*/DOWN/p
- /inet/s/netmask//
- /inet/s///p'
+ 1{ s/.*<UP,.*/UP/p
+ s/.*<.*/DOWN/p; }
+ /inet/{ s///
+ s/^[[:space:]]*//
+ s/netmask //p; }'
}
# Convert a netmask in hex format ($1) to dotted decimal format.
@@ -981,14 +982,15 @@ v4_config() {
}
# Obtain and output the inet6 information related to interface $1.
-# Should output '<UP/DOWN> <addr> <prefixlen> <rest of inet line> '.
+# Outputs '<UP/DOWN>\n<addr> <prefixlen> <rest of inet6 line>'.
v6_info() {
ifconfig $1 inet6 | sed -n '
- 1s/.*<UP,.*/UP/p
- 1s/.*<.*/DOWN/p
- /scopeid/d
- /inet6/s/prefixlen//
- /inet6/s///p'
+ 1{ s/.*<UP,.*/UP/p
+ s/.*<.*/DOWN/p; }
+ /inet6/{s///
+ /scopeid/d
+ s/^[[:space:]]*//
+ s/prefixlen //p; }'
}
# Set up IPv6 default route on interface $1.