I want to do the following for every user that logs into my linux box:
export PATH=$PATH:~/.path
And I don't know how to do that besides manually adding that line in every ~/.bashrc file.
Also, a cron job of mine runs a program and I want (for that cronjob) the PYTHONPATH set to something specific. will any .bashrc files affect the cronjob's environment? How do I change a cronjob's environment.
Also, I am now curious as to how to change what the PATH variable is on startup. Other programs seem to do this when they're installed, so how would I go about doing this?
Best Answer
Environments for shells
Essentially, anything that runs processes will tend to read a configuration file on starting up, and to affect the environment of that, you need to hit its configuration file.
For user shells, "obvious" places are
.profile
,.bashrc
,.bash_profile
(I think) and maybe a couple of others I don't remember. Obviously, more and others if you usezsh
,csh
,tcsh
or whatever as a shell.There are initialization files read by your windowing environment, which may be either KDE or Gnome. The particular window manager you run underneath that may also read a config file. I admit I don't know the names of those files even for my own installation.
Finally, there are usually "master" configuration files for all those environments somewhere in
/etc
. They provide defaults for stuff the users don't.I think that programs that install themselves conscientiously check the various possibilities. Various Linux distributions may offer some helper scripts for this.
cron
This one is a lot easier. For security reasons,
cron
only passes a couple of environment variables to subprocesses, ALWAYS. I thinkUSER
is one of those, andMAILTO
another. As far as I know, there's noPATH
set - this often annoys newbies. The environment of a cron job is completely different from your shell environment! Anything you want in the environment, you either pass in on the command line incrontab
, or you start up a script and let that set up whatever environment it needs.