On Fri, 09 Feb 2007 14:16:25 +0000
David Leverton <[EMAIL PROTECTED]> wrote:
> 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}}\""
> }
Very nice. We need to redirect 2>/dev/null for declare -p incase the
variable is not defined, but otherwise it works well in my tests too :)
Thanks
Roy
--
[email protected] mailing list