Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I want to edit /etc/profile:


  1. How do I have a variable that will automatically fill in the current user?
  2. What about hostname?
  3. Aren't these environment variables?
share|improve this question
up vote 9 down vote accepted

$USER should typically be set to the current user, and $HOSTNAME to the current hostname. If not, you can also get them from the output of whoami and hostname

Also, the user's home directory is not necessarily in /home/[username]. You should use the value of $HOME instead.

share|improve this answer
Why is it that when I type $HOSTNAME in my terminal command, it says: bash: /root: is a directory – Alex Oct 31 '09 at 22:21
No, you need to echo $HOSTNAME. If you just give bash a variable as a command, how is it supposed to know what action to take on it? – EEAA Oct 31 '09 at 22:31

If you wish to see all of your environmental variables available, use the following command:

bash$ set

Remember case sensitivity, for hostname you'll need $HOSTNAME, and $USER

bash$ echo $USER
bash$ echo $HOSTNAME
share|improve this answer

Another approach is to add a call to sys.addsitedir in rather than PYTHONPATH.

However since Python 2.6 you probably don't need to do either, because /home/$USER/.local/lib/python2.6/site-packages is automatically added to sys.path. This is a good choice of standard place to put user-specific modules/packages; you wouldn't really want to add the home directory itself as a module path as it contains all sorts of things that aren't modules, which could confuse imports.

See PEP370 for details.

share|improve this answer

In python, call os.uname() to get the hostname (and other details in an array).

share|improve this answer

Your Answer


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.