[Techtalk] using variables as part of variable name

dominik schramm dominik.schramm at gmxpro.net
Sat May 15 11:26:39 EST 2004


"dominik schramm" <dominik.schramm at gmxpro.net> writes:

>   pairs=("foo1:foo2" "bar1:bar2" "xy1:xy2")
>   for i in `seq 0 $((${#pairs[*]} - 1))`
>   do
>     cp ${pairs[$i]%:*} ${pairs[$i]#*:}
>   done

Oh, I only see emoticons where all the bash constructs should be :-)
It's probably wise to turn this feature off when looking at bash
scripts.

One minor addition:

It's probably better to write
  seq 0 $((${#pairs[*]} - 1)) | while read i

instead of "for i in ...".
Like this the script is ready for very large arrays.

regards,
dominik



More information about the Techtalk mailing list