We help IT Professionals succeed at work.

Unix Command to set Environment Variables

cgray1223
cgray1223 asked
on
Hello,

I'm trying to setup some environment variables on Unix and I believe I need to use the source command to "source" a file.  The .sh file I'm trying to source contains a bunch of export commands likes the below.  When I run $ source setenv.sh I get the below output.  I've removed all commands except for the ANT_HOME export and I still get the following error, any ideas?

output from $ source setenv.sh:
ANT_HOME=/auto/energywise/apache-ant-1.8.2: Command not found.
export: Command not found.

setenv.sh contents:
ANT_HOME=/aut/ew/apache-ant-1.8.2
export ANT_HOME



Comment
Watch Question

BRONZE EXPERT

Commented:
Just use

setenv.sh contents:
#!/bin/bash
export ANT_HOME=/aut/ew/apache-ant-1.8.2


And call it like
. ./setenv.sh

Author

Commented:
that yields:


$ . ./setenv.sh
/router/bin/.: Permission denied.
BRONZE EXPERT

Commented:
did you give execute permission to setenv.sh?

chmod +x setenv.sh

Author

Commented:
I believe these are correct:

-rwxr-xr-x  1 colgray eng 1020 Nov  2 10:12 setenv.sh

the directory its trying to use for the export (/aut/ew/apache-ant-1.8.2) has the below permissions, is that the problem?

drwxr-xr-x   6 darmak  eng      4096 Dec 20  2010 apache-ant-1.8.2
BRONZE EXPERT

Commented:
Ok, put quotes
setenv.sh contents:
#!/bin/bash
export ANT_HOME="/aut/ew/apache-ant-1.8.2"

Author

Commented:
same thing.  

Author

Commented:
looks like it was using the wrong command as I'm using c shell and the command needs to be setenv name value
BRONZE EXPERT

Commented:
First thing.  You probably do not have your path set correctly or something.  In particular, try running this command

export a=

On the command line.  If this produces an error, I want to see what error message it is.  

Second, which shell are you using?

If you were not using bash, remove #!/bin/bash from the file
BRONZE EXPERT

Commented:
Oops.

Yes, I was considering bash/ksh.
Commented:
For C shell, you do:  

setenv ANT_HOME /aut/ew/apache-ant-1.8.2

And, then call the file like:  . ./setenv.sh
BRONZE EXPERT
Top Expert 2007

Commented:
it is clear that you are using csh.

you need to convert your env variables settings in csh format:

e.g.

setenv PATH /usr/bin:/usr/ucb:/usr/local/bin
setenv PATH ${PATH}:~/bin

or

set path = ( /usr/bin /usr/ucb /usr/local/bin )

then in your .login file run

source ./setenv.sh
BRONZE EXPERT
Top Expert 2007

Commented:
I think you can not do below in csh

 . ./setenv.sh