3

I created a setenvj1.6 shell script in my /usr/local/bin directory, in cygwin (Windows 7).

setenvj1.6:

export PATH=/cygdrive/c/bea/bea10/bea10g3/jdk160_05/bin:$PATH
export JAVA_HOME=/cygdrive/c/bea/bea10/bea10g3/jdk160_05
echo Set for Java 1.6

when I run setenvj1.6, like this:

myuser@mycomp /usr/local/bin
$ setenvj1.6
Set for Java 1.6

I see that the script has run, but when I check if anything is set correctly, I see that my variables are not set:

myuser@mycomp /usr/local/bin
$ echo $JAVA_HOME

Similarly, if I echo $PATH, I get my usual PATH variable but without the directory I tried to add with export.

How do I get this to work?

I need a bash script like the one I specified that I can run after I've run cygwin so that I can change my paths to whatever I want. Thanks.

byronaltice
  • 623
  • 6
  • 18
  • 3
    The script runs in a sub-shell. It cannot affect its parents. You need to `source`/`.` load the script file instead of running it for this to work. – Etan Reisner Jul 28 '15 at 13:55
  • works if I do `source setenvj1.6` – byronaltice Jul 28 '15 at 14:18
  • Right, because `source` and `.` run the script in the *current* shell as opposed to a sub-shell. A shell function would be better than a script here for that reason. Functions (defined with `{...}` at least) run in the current shell. – Etan Reisner Jul 28 '15 at 14:22

0 Answers0