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" To: "Damo, David" , "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: References: X-OriginatingIP: 65.163.9.250 (wilson) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , 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" To: "Damo, David" , "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