Can't set variables in a while loop that is passed to the rest of the script.
Damo, David
David.Damo@CIBC.com
Thu Jan 14 23:40:00 GMT 2010
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
More information about the Cygwin
mailing list