Re: bash question



On 10/31/07, Dario Lesca <d.lesca@xxxxxxxxxx> 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@xxxxxxxxxx>

Is there a reason for using while instead of for?

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

Jacques B.

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list



Relevant Pages

  • Re: Echo vs Print
    ... >Echo can take multiple expressions (as in "echo ... I change a line from print to printf I only need to add a character. ... Possibly with a further reason that I use Perl a bit as well, ...
    (comp.lang.php)
  • Re: HELP! Scripting newbie question.
    ... printf "File: $file\n" ... There is nothing in your script to do the expand of the $1. ... insert a test by doing an echo $list or echo $1 in your srcipt to ...
    (comp.unix.solaris)
  • [Full-Disclosure] Sharutils buggy?
    ... attacker sends e-mail to root@some.host with a uuencoded attachment. ... setup the uuencode file in such a fashion as to make this work... ... printf "Changing directory to $tempdir/core..." ... echo "MESSAGE SENT!" ...
    (Full-Disclosure)
  • [Full-Disclosure] Sharutils buggy?
    ... attacker sends e-mail to root@some.host with a uuencoded attachment. ... setup the uuencode file in such a fashion as to make this work... ... printf "Changing directory to $tempdir/core..." ... echo "MESSAGE SENT!" ...
    (Full-Disclosure)
  • [Full-Disclosure] Sharutils buggy?
    ... attacker sends e-mail to root@some.host with a uuencoded attachment. ... setup the uuencode file in such a fashion as to make this work... ... printf "Changing directory to $tempdir/core..." ... echo "MESSAGE SENT!" ...
    (Full-Disclosure)