2009/9/19 Jeff Waugh <[email protected]> > <quote who="Daniel Bush"> > > > Writing a little utility to help me on something but having trouble. > > Why does f stay blank? > > Answer (which I think was mentioned in earlier responses): The parent shell > doesn't have access to the subshell's scope. The usual way of doing this is > to provide output from the loop into a variable, like this: > > PANTS=$(echo "foo|bar" | while ... echo -n $F ...) > > Solution: Depends on the actual task rather than the example. :-) > > > d...@lin4:test$ echo "foo|bar" | awk 'BEGIN{RS="|"}{ print $1 }' | while > > read s; do echo $s; f=$s; done; echo "'$f'" > > foo > > bar > > '' > > A couple of thoughts (note that I always use caps for variables for > clarity)... > > echo "foo|bar" | tr '|' '\n' | while read S >
You trying to make my awk look awkward? :) yeah, I do caps for important stuff but I like dropping to lower for loop and throw away variables. I sometimes also scope them by using 'local' within a bash function. Cheers, Daniel -- Daniel Bush -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
