bash question

Jacques B. jjrboucher at gmail.com
Wed Oct 31 20:31:36 UTC 2007


On 10/31/07, Dario Lesca <d.lesca at solinos.it> wrote:
> In this shell script:
>
> > #!/bin/bash
> > i=0
> >
> > printf "a a a\nb b b\nc c c\n" |
> > while read x
> > do
> >         i=$[i+1]
> >         echo "$x: ($i)"
> > done
> >
> > echo $i
>
> with this output:
>
> > a a a: (1)
> > b b b: (2)
> > c c c: (3)
> > 0
>
> How to I can get the value (3) for $i out of the while loop?
>
> Many thanks
>
> --
> Dario Lesca <d.lesca at solinos.it>

Is there a  reason for using while instead of for?

for x in $(ls dir/)
do
   .....
done

Jacques B.




More information about the fedora-list mailing list