This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


The pipe is what spawns the sub shell.  In Unix the last process runs in your 
current shell.  In Linux the first process of the pipe runs in the current 
shell.  The difference is that when the while statement (which is run in the 
sub shell) finishes the sub shell dies and any variable changes are lost.  In 
Unix the variables remain in the current shell.

Sincerely,

Brian S. Wilson
===================================================================
Home: (678) 376-9258       Cell: (678) 232-9357     Wilson@ds.net
===================================================================

---------- Original Message -----------
From: "Damo, David" <David.Damo@CIBC.com>
To: "Damo, David" <David.Damo@CIBC.com>, "cygwin@cygwin.com" 	
<cygwin@cygwin.com>
Sent: Thu, 14 Jan 2010 18:23:28 -0500
Subject: RE: Can't set variables in a while loop that is passed to the rest  
of the script.

> 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
> 
> -----Original Message-----
> From: Damo, David 
> Sent: Thursday, January 14, 2010 5:40 PM
> To: 'cygwin@cygwin.com'
> Subject: Can't set variables in a while loop that is passed to the 
> rest of the script.
> 
> Hi,
> 
> I had a script that worked on UNIX, but on Cygwin it does not work. 
> When I set a variable in a while loop I can't use it after the loop. 
> However, this worked in UNIX. Any ideas why? All variables set after 
> the done command are blank, but can be seen in the while loop.
> 
> propfile=${SCRIPT_HOME}/${propfilename}
> sed 's/\$/^/g' $propfile | while read line
> do
> 	export david="Hello"
> 	nvpair=$(echo $line | awk -F"=" '{print $1,$2}')
> 	set -- $nvpair
> 	if [ ! "$1" = ""  ]; then
> 		eval "$1"=\"$2\"
> 	fi
> done
> 
> echo $david
> 
> echo "Setting siteminder_home"
> echo $siteminder_home
> 
> Thanks,
> 
> David
> 
> --
> 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
------- End of Original Message -------


--
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]