Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 3 down vote accepted

Use conditionals in your ~/.profile.

case `uname` in
  Solaris)
    PATH=/usr/xpg6/bin:/usr/xpg4/bin:$PATH
    LD_LIBRARY_PATH=$HOME/lib/solaris
    export LD_LIBRARY_PATH;;
esac

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

case `uname` in
  Solaris)
    alias df='df -k' du='du -k'
    alias ls='ls -F';;
  Linux)
    alias ls='ls --color';;
esac
share|improve this answer
add comment

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
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 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
add comment

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.