Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

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

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

2 Answers 2

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.

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

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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