up vote 4 down vote favorite
1
share [g+] share [fb]

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?

link|improve this question

67% accept rate
1  
stack overflow is for programming. this is a system admin question, and belongs on serverfault. – Peter Jul 20 '10 at 20:34
Not necessarily. Though it's not entirely clear, I'm assuming he's asking how to do this programmatically. – Carl Smotricz Jul 20 '10 at 20:43
feedback

migrated from stackoverflow.com Jul 20 '10 at 20:47

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 3 down vote accepted

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 use zsh, 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 think USER is one of those, and MAILTO another. As far as I know, there's no PATH 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 in crontab, or you start up a script and let that set up whatever environment it needs.

link|improve this answer
actually, I just found a cron example in SO: stackoverflow.com/questions/3327695/… – Thr4wn Jul 25 '10 at 2:22
feedback

To apply a bashrc change to all users, you can modify /etc/bash.bashrc (This is for Ubuntu).

Also, as indicated in the answer above, make sure that this file is sourced by /etc/profile.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.