Ask Different is a question and answer site for power users of Apple hardware and software. 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

My /home/myusername/ directory is provided through a network, and looks exactly the same on my Linux machine and my Mac Mini. I'd like to add to PATH a directory of Mac-specific software in my home, e.g. /home/myusername/SW/bin_mac/ and have this happen only when I'm doing command line stuff on the Mac, and not have PATH contain this when on Linux. If I edit .bashrc (or tcsh's equivalent) it'll affect PATH in both cases. What are some tricks to do this?

share|improve this question
up vote 5 down vote accepted

Test the output of uname; it will be Darwin on OS X and Linux on Linux.

if [[ $(uname) == Darwin ]]; then
    export PATH="$HOME/SW/bin_mac:$PATH"

Alternately, you could just add an appropriate directory on each machine, which will be useful if you find yourself needing a separate Linux bin directory as well in the future.

export PATH="$HOME/SW/bin_$(uname):..."

and either mv or ln -s your bin_mac to bin_Darwin; then you can create a bin_Linux directory in the future if you need it, and it'll just work.

(You could also test $HOSTTYPE, which is set by bash, but it contains more information than you're likely to need.)

share|improve this answer
The second solution looks great - a tidy one liner, and yes I may need to deal with multiple platforms and more than just PATH. – DarenW Jun 29 '11 at 20:17

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.