Can't set variables in a while loop that is passed to the rest of the script.

Jeremy Bopp jeremy@bopp.net
Fri Jan 15 00:43:00 GMT 2010


On 1/14/2010 5:23 PM, Damo, David wrote:
> Hi,
> 
> I have fixed the problem. It seems in cygwin it spawns a subshell even under bash. I used a for loop instead and everything worked nicely.
> 
> for line in `sed 's/\$/^/g' $propfile`
> do
> 	nvpair=$(echo $line | awk -F"=" '{print $1,$2}')
> 	set -- $nvpair
> 	if [ ! "$1" = ""  ]; then
> 		eval "$1"=\"$2\"
> 	fi
> done

Interesting.  Your workaround should work fine as long as the propfile
is not too large, I think.  However, wouldn't it be easier to source a
properly massaged version of propfile instead?

sed 's/\$/^/g' $propfile | grep -v '^=' >$propfile.tmp
. $propfile.tmp
rm $propfile.tmp

-Jeremy

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list