Afficher un message
Vieux 01/11/2006, 10h00   #9
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
 
Page generated in 0,05373 seconds with 9 queries