Link to home
Start Free TrialLog in
Avatar of Tonyboy
Tonyboy

asked on

Cross-shell environment variables

Dear group,

Is there a way to set a certain environmental ($ENV) variable so that no matter what shell is started, by no matter which user, the variable is present.

More specifically, I want to set $ENV{'PERL5LIB'} to point to my program directory so that no matter where my programs are started from, no matter which user (including nobody and root), the proper directory will be included in @INC.

...but I'm getting ahead of myself. Any help is appreciated.

Thanks,
- Tonyboy
Avatar of Peter Kwan
Peter Kwan
Flag of Hong Kong image

Add the following your /etc/profile (or equivalent "profile" file, depending on your linux distribution):

set PERL5LIB="value"
export PERL5LIB

or if your distribution supports setenv, use

setenv PERL5LIB "value"
export PERL5LIB

Please tell us if this does not work for you.
Avatar of Tonyboy
Tonyboy

ASKER

...but won't this simply add the PERL5LIB variable to the bash shell users? tcsh, csh and sh shell users don't source the /etc/profile file, as far as I know.
As far as i know, for sh users,  they are using /etc/profile.
For csh,tcsh users, they are using /etc/cshrc.login

If you have both, then you should edit both files.
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany 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
Avatar of Tonyboy

ASKER

What about jobs run by cron? What about scripts run by Apache? Do these files get sourced when the shells are started by other programs?
> What about jobs run by cron?
cron uses sh by default, so /etc/profile matches.
If the user uses another shell in her/his crontab, they need to source the appropriate scripts, but AFAIK the cannot cross the limits set by the parent shell (never checked it).

> What about scripts run by Apache?
Apache uses its own user (www, nobody), usually. So the same applies as for cron.

> .. shells are started by other programs?
Depends on the shell.
But i.g. you cannot cross the limits set by the parent.