[NTLUG:Discuss] Simple bash shell question

Ed Leach ntlug at levelofdetail.com
Fri Mar 30 16:00:48 CDT 2007


This should help:

   http://wooledge.org/mywiki/BashFaq#faq24

(Big page loads slowly.)

------------------

. Daniel wrote:
> This is probably so elementary that maybe I shouldn't bother asking, but 
> I'd like to know.
> 
> Given the following:
> ----
> #!/bin/sh
> fcount=0
> ls -1 *.mpg | while read filename ; do
>     fcount=$(expr $fcount + 1)
>     echo $fcount
> done
> echo $fcount
> ----
> 
> why do I get the following output?
> ----
> [daniel at alpha ~]$ test.sh
> 1
> 2
> 3
> 4
> 0
> ----
> 
> I would expect:
> 1 
> 2 
> 3 
> 4 
> 4
> 
> Where is my thinking broken?
> 
> _________________________________________________________________
> 春は出会いと別れの季節。メッセンジャーがあれば鬼に金棒!つなげようメッセの輪
>  http://messenger.live.jp/ 
> 
> 
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
> 



More information about the Discuss mailing list