RE: bash while read question

2010-05-06 Thread Evuraan
2010/5/5 CyberLeo Kitsana cyber...@cyberleo.net:
 On 05/05/2010 08:25 PM, Evuraan wrote:
 I cant figure out why the variable in in loop2 does not hike to +1?
 (its a friday, i am dazed, I admit. but this should not be a mystery!)
 any help would be much appreciated.
 snip
 $ cat loop2
 #! /bin/bash

 date  /tmp/somefile
 b=1
 cat /tmp/somefile | while read blah; do
 let b=(b+1)
 done
 echo variable is $b

 This particular syntax executes the 'while' block in a subshell. The
 variables set or altered in the subshell are never propagated back up to
 the parent shell.

duh, i get it now, anytime stuff is piped , a subshell is evoked:

http://tldp.org/LDP/abs/html/subshells.html says,

snip
Redirecting I/O to a subshell uses the | pipe operator, as in ls -al
| (command).
/snip

thanks for the reset..!

 --
 Fuzzy love,
 -CyberLeo


___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


bash while read question

2010-05-05 Thread Evuraan
I cant figure out why the variable in in loop2 does not hike to +1?
(its a friday, i am dazed, I admit. but this should not be a mystery!)
any help would be much appreciated.


$ cat loop1
#! /bin/bash

date  /tmp/somefile
b=1
while read blah; do
let b=(b+1)
done   /tmp/somefile
echo variable is $b

$ cat loop2
#! /bin/bash

date  /tmp/somefile
b=1
cat /tmp/somefile | while read blah; do
let b=(b+1)
done
echo variable is $b


$ ./loop1
variable is 2

$ ./loop2
variable is 1
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: bash while read question

2010-05-05 Thread CyberLeo Kitsana
On 05/05/2010 08:25 PM, Evuraan wrote:
 I cant figure out why the variable in in loop2 does not hike to +1?
 (its a friday, i am dazed, I admit. but this should not be a mystery!)
 any help would be much appreciated.
 snip
 $ cat loop2
 #! /bin/bash
 
 date  /tmp/somefile
 b=1
 cat /tmp/somefile | while read blah; do
 let b=(b+1)
 done
 echo variable is $b

This particular syntax executes the 'while' block in a subshell. The
variables set or altered in the subshell are never propagated back up to
the parent shell.

-- 
Fuzzy love,
-CyberLeo
Technical Administrator
CyberLeo.Net Webhosting
http://www.CyberLeo.Net
cyber...@cyberleo.net

Furry Peace! - http://.fur.com/peace/
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org