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?


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';;

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
  • 1
    .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. superuser.com/questions/183870/… . 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 'SO- stop being evil' 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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