It's not working for a couple of reasons:
To run a script as an executable the first line has to tell the shell what program (i.e. which shell) should run the script, so you should start:
#!/bin/bash
or whichever shell you want (but see the note below).
Secondly, you can't execute this in tcsh because it uses a different syntax. You don't export environment variables, you use setenv with no equals sign. Additionally, $(command) means nothing to tcsh.
Another problem though is that if you run this script from a different shell, the variables set in it won't be carried back when it completes: when you run . ./script.sh it runs the script through the currently running shell.
Your best solution is to have two versions, one in this format, and one that works with tcsh, and to put them in your startup scripts, i.e ~/.bashrc or ~/.tcshrc.