Re: bash question



On 10/31/07, Jacques B. <jjrboucher@xxxxxxxxx> wrote:
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.


The one caution when dealing with path/filenames is spaces. That was
discussed not long ago and a few suggestions were given, mine being to
change the $IFS variable but others were suggested that also worked if
I recall.

Jacques B.

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



Relevant Pages

  • Re: shell variable security
    ... echo "Invalid character!" ... In the meantime I echo Jonathan's question. ... semi-colon and all. ... Jacques b. ...
    (Fedora)
  • Failed :-( Re: PC clock
    ... Jacques Guy wrote: ... enough hypothesizing. ... @ECHO OFF ... Bear with me once again. ...
    (sci.lang)
  • Re: Failed :-( Re: PC clock
    ... > Jacques Guy wrote: ... But instead of adjusting it by one hour, ... > @ECHO OFF ... > Bear with me once again. ...
    (sci.lang)
  • Re: bash question
    ... echo "$x: " ... Is there a reason for using while instead of for? ... Jacques B. ...
    (Fedora)
  • 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)