Link to home
Start Free TrialLog in
Avatar of cgray1223
cgray1223

asked on

Unix Command to set Environment Variables

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



Avatar of farzanj
farzanj
Flag of Canada image

Just use

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


And call it like
. ./setenv.sh
Avatar of cgray1223
cgray1223

ASKER

that yields:


$ . ./setenv.sh
/router/bin/.: Permission denied.
did you give execute permission to setenv.sh?

chmod +x setenv.sh
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
Ok, put quotes
setenv.sh contents:
#!/bin/bash
export ANT_HOME="/aut/ew/apache-ant-1.8.2"
same thing.  
looks like it was using the wrong command as I'm using c shell and the command needs to be setenv name value
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
Oops.

Yes, I was considering bash/ksh.
ASKER CERTIFIED SOLUTION
Avatar of sentner
sentner
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
I think you can not do below in csh

 . ./setenv.sh