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.

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
fi

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

4 Answers 4

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

I'd probably do something like this:

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

There is an environment variable:

echo $OSTYPE
share|improve this answer
add comment
 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
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.