From 930f4021b1904b9c46c41c70b99d6e0620a1b59d Mon Sep 17 00:00:00 2001 From: Christian Ruppert Date: Wed, 21 Sep 2011 00:21:43 +0200 Subject: Add a new helper functions for _{flatten,get}_array A new helper function (_array_helper) since both, the _flatten_array and _get_array function share partially the same code. We also reduce multiple whitespace to a single space, remove leading newlines as well as skipping "empty" lines. This makes the data returned by _{flatten,get}_array much nicer than before. It also fixes bug 366677 where net-tools having trouble with the whitespace mentioned above. iproute2 was not affected. Reported-by: Andrew Maltsev X-Gentoo-Bug: 366677 X-Gentoo-Bug-URL: https://bugs.gentoo.org/366677 --- init.d/net.lo.in | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/init.d/net.lo.in b/init.d/net.lo.in index 2f052ca..9b6bf64 100644 --- a/init.d/net.lo.in +++ b/init.d/net.lo.in @@ -41,6 +41,15 @@ depend() done } +_array_helper() { + local _a= + + eval _a=\$$1 + _a=$(echo "${_a}" | sed -e 's:^[[:space:]]*::' -e 's:[[:space:]]*$::' -e '/^$/d' -e 's:[[:space:]]\{1,\}: :g') + + [ -n "${_a}" ] && printf "%s\n" "${_a}" +} + # Support bash arrays - sigh _get_array() { @@ -60,10 +69,7 @@ _get_array() esac fi - eval _a=\$$1 - printf "%s" "${_a}" - printf "\n" - [ -n "${_a}" ] + _array_helper $1 } # Flatten bash arrays to simple strings @@ -84,10 +90,7 @@ _flatten_array() esac fi - eval _a=\$$1 - printf "%s" "${_a}" - printf "\n" - [ -n "${_a}" ] + _array_helper $1 } _wait_for_carrier() -- cgit v1.2.3