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

i was thinking in way that before run my script , evaluate which operating system that user use ubuntu or solaris , am using this because there is some differences
in command option in each OS such as sed .. , i was trying the following :

sysEval=`grep "ubuntu" | uname -a`

if [ sysEval ]; then

.......some command 

else ....... some command

NOTE That my script will run only in ubuntu or solaris
seems not working !

share|improve this question
This question makes sense and has multiple upvoted answers. But it appears it may soon be closed. It would be good if at least one person who has voted to close this would explain why this should be closed. – Eliah Kagan Apr 1 '13 at 0:21
up vote 3 down vote accepted

Instead of parsing uname -a a better idea would be parsing output of cat /etc/*release*.

share|improve this answer

I'd probably do something like this:

os=$(uname -s)
case $os in
    distro=$(lsb_release -si)
    case $distro in
        echo "Ubuntu, great!"
        echo "Sorry, Linux distribution '$distro' is not supported"
        exit 1
    echo "SunOS, great!"
    echo "Sorry, OS '$os' is not supported"
    exit 1
share|improve this answer
nice and clean code as usual .... – moata_u Mar 12 '11 at 10:29

There is an environment variable:

echo $OSTYPE
share|improve this answer
 sysEval=cat /etc/*release* | awk 'FNR == 1 {print $1 }' | cut -d\= -f2
share|improve this answer
which sysEval will equal = ubuntu , if not .....Solaris – moata_u Mar 11 '11 at 9:31
sysEval="$(cat .......... -f2)" – Peter.O Mar 11 '11 at 11:54

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.