The technique you are using (adding a -V) should work. One possibility since you are specifying the shell with -S is that grid engine is configured to launch /bin/bash as a login shell and your profile scripts are stomping all over the environment you are trying to pass to the job.
Try using qstat -xml -j
on the job while it is queued/running to see what environment variables grid engine is trying to pass to the job.
Try adding an env
command to the script to see what variables are set.
Try adding shopt -q login_shell;echo $?
in the script to tell you if it is being run as a login shell.
To list out shells that are configured as login shells in grid engine try:
SGE_SINGLE_LINE=true qconf -sconf|grep ^login_shells