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 <am@ejelta.com>
X-Gentoo-Bug: 366677
X-Gentoo-Bug-URL: https://bugs.gentoo.org/366677
This commit is contained in:
Christian Ruppert 2011-09-21 00:21:43 +02:00
parent bf49e59e3e
commit 930f4021b1

View File

@ -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()