rendered paste bodybonsai@mainserver:~$ fooarr=(* "foo"$'\n'"bar")
bonsai@mainserver:~$ getarrdecl fooarr "${fooarr[@]}"
fooarr=([0]"bin"[1]"dcc"[2]"Desktop"[3]"devel"[4]"ekiga_development"[5]"etc"[6]"gtk-gnutella-downloads"[7]"icons"[8]"incoming"[9]"ip-minds.de"[10]"ircstats"[11]"latex"[12]"ldap.conf"[13]"log"[14]"Mail"[15]"mnt"[16]"net"[17]"News"[18]"plan9"[19]"sabine_elterns.txt"[20]"sources"[21]"Star Trek Enterprise - S01 E16 - Allein.avi"[22]"tacctd_devel"[23]"tests"[24]"torrentDL"[25]"foo
bar")
improved, with checking. obviously remove the checking if you want.
getarrdecl () {
local name=$1 f="'" t="'\''" i=0 x="${1}=(";
shift;
local args=(); args=( "$@" );
while [ $# -ne 0 ] ; do
x="${x} [$((count++))]='${1//${f}/${t}}'"; shift;
done
x="${x} )"
echo "$x"
bash -xc "$x && n=0 && while [ \$# -ne 0 ]; do
[ \"\$1\" = \"\${$name[\$n]}\" ] || { echo bad \$n; exit 1; } &&
let n=n+1 && shift;
done; echo \$n good; exit 0" arg0 "${args[@]}"
}
getarrdecl "$@"; exit