Roy Marples wrote:
On Fri, 09 Feb 2007 01:03:04 -0800
Donnie Berkholz <[EMAIL PROTECTED]> wrote:
How about this?
replace="
'4d 1280 768 24'
'5c 1400 1050 16'
"
Actually, that may work better than my delimited with ; approach.
We could then do
eval set -- "${replace}"
for x in "$@" ; do
....
done
Would something like the following be acceptable? If the user uses bash
they can use an array, otherwise (or if they prefer) they can do the
"'...' '...'" thing, transparently to the code that uses the variable.
Could do with more testing of edge cases, but it seems to work well for
me - in bash as is, and in dash and busybox with the "foo" section
commented out.
get_array() {
local var="${1}"
if [ -n "${BASH}" ]; then
declaration="$( declare -p "${var}" )"
case "${declaration}" in
"declare -a"*)
echo "set -- \"[EMAIL PROTECTED]""
return
esac
fi
echo "eval set -- \"\${${var}}\""
}
foo=( 1 2 3 )
eval $(get_array foo)
for x in "$@"; do
echo $x
done
bar="1 2 3"
eval $(get_array bar)
for x in "$@"; do
echo $x
done
--
gentoo-dev@gentoo.org mailing list