Re: double "triangle" loop for $* ?
2006-10-31, 20:23(-05), Chris F.A. Johnson:
[...]
> To use "$@" is more complicated in a POSIX shell, but
> straightforward in bash:
>
> unset z
> for x in $*
ITYM
for x in "$@"
> do
> z[${#z[@]}]=$x
> for y in "${z[@]}"
> do
> : body
> done
In the OP's requirement z[...] should be after the for y loop.
> done
[...]
It may reveal more legible in zsh:
z=()
for x do
for y in "$z[@]"; do
: body
done
z+=$x
done
Also:
awk '
BEGIN {
for (i = 1; i < ARGC; i++) {
for (j = 1; j < i; j++) {
# body ARGV[i] ARGV[j]
}
}
exit
}' "$@"
may reveal more appropriate if the purpose is to do arithmetic
or text manipulation operations over the elements.
--
Stéphane
|