1834441 Members
2407 Online
110067 Solutions
New Discussion

Re: setenv in csh

 
george_57
Occasional Advisor

setenv in csh

Hi,
Im trying to set an environment through a script.
for eg..a simple script with this line below:
------------------------
#!/bin/csh -f
setenv version /prg/1.0.1/
--------------------------

when i put the above 2 lines in a script and execute it. nothing happens it just returns back to the prompt with out changing any environment or giving any error msg.

Can somebody help me..or is there a better way of setting an environment through c script
Thanks in advance




none
5 REPLIES 5
george_57
Occasional Advisor

Re: setenv in csh

an additional info is that when i try typing :
setenv version /prg/1.0.1/

in the command prompt it works fine.
none
H.Merijn Brand (procura
Honored Contributor

Re: setenv in csh

Simple answer: you can't. Period. Environment variables are scoped to the process where it is set (the script) and all it's children. i.o.w. it's localized from that point on, and loses the setting on exit of the scope (script).

What you need is the dot command, whcih invokes the script /as if it were script source/

. script

is like #include in C-source files. Due to the fact that is executed in-line, the scope promotes to the current script, and will be visible after the call.

HTH
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor

Re: setenv in csh

Uhhh, one addition. The dot command is sh-syntax, not csh-syntax, but I got soooo used to my alias, that it is the same for me :)


alias .=source

so the previous post should have read: what you need is the 'source'; command
Enjoy, Have FUN! H.Merijn
Judy Traynor
Valued Contributor

Re: setenv in csh

try to just source your script

env
source scriptname
env

see if that works.
Sail With the Wind
maafa
Advisor

Re: setenv in csh

put the line in your .cshrc file and source it.

.cshrc playe the same role as .profile in sh/ksh