I can tell you this is the craziest thing I have seen in a long time.
I have this (part of) sh script running on CentOS 5.4:
# Check GOLD_DIR`
echo $GOLD_DIR"<--"
#export GOLD_DIR=/share/apps/GOLD_Suite/GOLD <uncommenting this line works!!
if [ "X$GOLD_DIR" =  "X" ] ; then
  echo "ERROR: GOLD_DIR is (probably) not set on host ${HostName}" >> ${3}
  exit 1
fi
And this gives the following output:
/share/apps/GOLD_Suite/GOLD<-- 
Waiting for 5 seconds ..... Testing output
The test script did spawn a job (i.e. PVM ran OK), 
but errors were detected in the test script output 
on the host machine: Below is the output
ERROR: GOLD_DIR is (probably) not set on host xxx.yyy.local
As you can see the GOLD_DIR variable is set (the script finds it as shown by the output with postfixed "<--") !  If I uncomment the export of the GOLD_DIR variable in the script code (first snippet) everything works.
EDIT: GOLD_DIR is exported in /etc/profile (using export GOLD_DIR=/share/apps/GOLD_Suite/GOLD)
Any ideas why?
Note1: I don't know if this is important but this is a spawn script on PVM.
Note2: The script is written in sh #!/bin/sh but I am using bash...
Edit3: I GOT IT TO WORK BUT I DONT KNOW WHY! - Ok so what I did was rename the hostname (with sudo hostname abc) to the name of the machine I ssh into (e.g. abc).  Before the PVM was listing the full name of the machine abc.mycompany.local.  Note that both abc.mycompany.local and abc are the same machine.
                        
So the var is set. If you just do
export GOLD_DIRinstead of commented line (without setting the value), will it work?Also. It's an isolated case? Is it bash there on CentOS? Try to use [[ ]] to check what's working wrong.