Super User is a question and answer site for computer enthusiasts and power users. 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

I share my .bashrc (all my dotfiles, actually) between ubuntu and archlinux. Since the paths may vary between them, I'd like to run some commands only on ubuntu (and others only on archlinux). How can i detect whether I am running ubuntu inside the .bashrc file? Detecting Debian will probably work.

share|improve this question
up vote 1 down vote accepted

The result of uname -v on my machine contains "Ubuntu" - Maybe you can use that? However, a more portable solution would be to check for the existence of the paths instead:

if [ -x "$FOO" ]
    "$FOO" --option

This is the standard way in GNU makefiles.

share|improve this answer

Think of it as different computers, not different operating systems:

if [[ -f $file ]]; then
    . "$file"
share|improve this answer
but i'm sharing on github, so it'd be nice if i could think of OS. – barraponto Mar 12 '11 at 4:38
@barraponto: in that case it's "Linux" and "Linux". – grawity Mar 12 '11 at 14:04

REVISED: the original version doesn't work on Ubuntu 10.04 which does not mention Ubuntu in uname -v. The /etc/lsb-release file is much better for this purpose as it has an explicit DISTRIB_ID line set to Ubuntu.

Based on l0b0's response, this sh script detects Ubuntu with an if statement. As others have pointed out, depending on what you're doing it may be more appropriate to detect particular programs or features, but as someone who has written Ubuntu-specific installers I appreciate that sometimes a simple smoke test that someone is not misapplying them is all you want.


UBUNTU=`grep -i ubuntu /etc/lsb-release | wc -l`
if [ "$UBUNTU" != "0" ] ; then
  echo "This is so totally Ubuntu!"
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .