Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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

We are using NIS and Automount for *nix developing hosts. So I can login any host with the same identity and same home directory.

I hope to set different environment variables when login different hosts. For example, I want to set the LD_LIBRARY_PATH with some value when login the solaris host. However I don't set it when login the linux host.

How should I do?

share|improve this question
up vote 3 down vote accepted

Use conditionals in your ~/.profile.

case `uname` in
    export LD_LIBRARY_PATH;;

You might also want to set some aliases and other shell settings differently. These go into your ~/.bashrc or ~/.zshrc.

case `uname` in
    alias df='df -k' du='du -k'
    alias ls='ls -F';;
    alias ls='ls --color';;
share|improve this answer

I am assuming you use bash as your shell.

Edit your user's ~/.bashrc and add the following line

[[ "$(uname)" != "Linux" ]] && export LD_LIBRARY_PATH=/solaris_path:$LD_LIBRARY_PATH
share|improve this answer
.bashrc is not the right place to define environment variables as they will only be defined in programs started from a terminal, not programs started from the window manager menu. See e.g.… . LD_LIBRARY_PATH is an exception though: you may want to define it in .bashrc in addition to .profile, because on some systems (including Ubuntu) some terminals are setuid or setgid in order to write to utmp (quod google), causing them to drop LD_LIBRARY_PATH. – Gilles Nov 25 '10 at 2:11
@Gilles, you're right. LD_LIBRARY_PATH is an exception, it need be defined in .bashrc. Then it works on Solaris. – Kane Nov 25 '10 at 2:38

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.