environment variable

Hi,

I have to set bunch of variables and all other programs like make,
perl will use them ..

Here are my constraints and requirements ...

The variables have to be set by executing a script that runs
in c shell. I cannot source the script since people who use this
script might be on other shell (bash, ksh)

When I use setenv in a script and execute that script then
I dont see these values getting reflected in current shell.
That is, once the script comes out the env. variable is not
set to expected value.

However, when I source the script the value is set properly.

What is the way out ?

Regards,
Sharan

I dont use c-shell. But I assume this should work.

. ./env.csh

env.csh is the script which contains the env variables.

That works in korn shell. In C shell it can be executed by simply typing the script name. But the point is that if the script is executed this way then variables set
using setenv are not visible in shell where script got executed

source ./env.csh

I think I did not communicate properly ..

I cannot use the above approach because the script can be run by users
who might not be on korn or bash. So sourcing is ruled out and the
script has to be executed. If that is done then the variables set using
setenv are not seen once I come out of the script or in other programs
like make files ..

Put your script into part of the login script - I assume csh logins respect /etc/profile.
csh supports functions, I think. Create a function in /etc/profile. When the user needs to create the variable, she types the function name at the command line.

Well that (putting into login script is not a good idea for me) since these are
project specific variables and one might be doing multiple projects at the
same time. Is is guaranteed that these functions will run if called from
any shell like korn or bash, because that is the primary reason why things
are getting so complicated for me.

Unless I'm making a lot of bad assumptions, you are making this far harder than it needs to be.

These variables have to be defined for something (not everything) to work for some users, at least some of the time, and under different shells. It has to be invoked on demand, otherwise it is not in effect. You did not specify that the environment has to go away after the user decides to stop using it. :: Your requirments definition.

Possible solutions:

  1. create a shell-aware driver script to run the correct version of script needed.

  2. Create two different versions of the script to run under csh, ksh. Teach the users what to do - which command sets variables for what shell.

  3. define a function(s) that the user executes when he/she wants to set the variables.

  4. Create a special account(s) on the system to handle this one environment.
    This is very common - ftp/sftp accounts are an example.

  5. create a script that is the ONLY way to enter the environment. The script takes over being the environment. This is commonly done to restrict users and is often written in perl or python. When the user exits the environment goes away of course.

If one of these does not meet your needs, you are going to have to explicitly define all your requirements up front.

Well the whole idea is to avoid having different script for each shell, otherwise
my probelm is solved.

I am putting my requirements as explicit as possible below

1) we are creating a framework for a certain application

2) the users can do development work using this framework

3) the users can be under any shell

4) the framework consists mainly of shell scripts, makefiles and perl scripts

5) the users, first execute the shell script to setup neccessary variables.
These variables are refered in makefiles and perl scripts.
These scripts cannot be sourced by users since they can be on bash
or korn shell.

6) Once they setup the project variables they can start their development work
and fill up make templates.

Issue :

I write a shell script that assigns values to project variables. When I execute this
script (in C shell itself) then these variable vallues are not seen once the script
completes execution and exits. The variables are set using setenv assuming they are more persistent than variables set using "set"