Re: Bash script for files with spaces in the filenames

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



steveo@xxxxxxxxxxx ("Steven W. Orr") writes:
> Just be careful with this construct. It may do what you want but be aware 
> of what it won't do:
> 
> cnt=0
> find | while read foo 
> do
>   echo "File name $cnt = $foo" 
>   cnt=$(( cnt + 1 ))
> done
> echo $cnt
> 
> This will print out an incrementing counter in the loop but it will 
> print out a 0 for the final echo. That's because the instance of cnt in 
> the loop is in a seperate process from the instance out of the loop. They 
> are seperate variables. It's the pipe that creates the child.

Correct if you want to do something like that you need a construct similar
to this one:
cnt=0
find > /tmp/somefile
while read foo
  echo "File name $cnt = $foo" 
  cnt=$(( cnt + 1 ))
done < /tmp/somfile
echo $cnt

-- 
Mathieu Chouquet-Stringer
    "Le disparu, si l'on vénère sa mémoire, est plus présent et
                 plus puissant que le vivant".
           -- Antoine de Saint-Exupéry, Citadelle --


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux