delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/01/15/14:42:20

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_PASS
X-Spam-Check-By: sourceware.org
From: "Brian Wilson" <wilson AT ds DOT net>
To: "Damo, David" <David DOT Damo AT CIBC DOT com>,
"cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
Subject: RE: Can't set variables in a while loop that is passed to the rest of the script.
Date: Fri, 15 Jan 2010 14:42:07 -0500
Message-Id: <20100115194014.M26660@ds.net>
In-Reply-To: <EDF49EC9787F914CA157FF6927D65A88302633AB82@CBMCC-X7-MBX10.ad.cibc.com>
References: <EDF49EC9787F914CA157FF6927D65A88302633AB82 AT CBMCC-X7-MBX10 DOT ad DOT cibc DOT com>
X-OriginatingIP: 65.163.9.250 (wilson)
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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 AT ds DOT net
===================================================================

---------- Original Message -----------
From: "Damo, David" <David DOT Damo AT CIBC DOT com>
To: "Damo, David" <David DOT Damo AT CIBC DOT com>, "cygwin AT cygwin DOT com" 	
<cygwin AT cygwin DOT 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 AT cygwin DOT 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019