Afficher un message
Vieux 01/11/2006, 06h22   #3
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: double "triangle" loop for $* ?

On 31 Oct 2006 16:11:39 -0800, Yakov
<iler.ml@gmail.com> wrote:
> I'm curious how to write the double "triangle" loop for $* in posix sh
> analogous to this loop: for(k=0; k<N;k++) for(j=0; j<k; j++) body;
> preferably in posix shell. I'm experienced shell scripter but here,
> I'm stumped: for x in $*; do for y in ????; do body; done; done;
> (???? must become the slice of $* list from $1 to one before
> the element represented by $x)
>
> Is it possible at all ? bash-specific solutions are welcome, too,
> but posix sh are preferred.
>

Bash version 2 or later, zsh, and I think ksh93 have the syntax
for (( k=0; k<N; k++ ))

Some systems have the "seq" command:
for x in `seq 1 10`


--
Baker's First Law of Federal Geometry:
A block grant is a solid mass of money surrounded on all sides by
governors.
  Réponse avec citation
 
Page generated in 0,04660 seconds with 9 queries