Testing Unix type (BSD/S5) in shell?

Testing Unix type (BSD/S5) in shell?

Post by Marian Ge » Fri, 05 Jan 1996 04:00:00



I am developing a large body of Korn shell scripts and would like to make
them as portable as possible.  I believe that I can definitely assume that
the execution environment is Berkeley Unix if the file /vmunix exists.  I
believe that I can assume that I'm in System V Unix if the file /etc/inittab
exists.  Are these statements correct?  Is there a better way?

And how about distinguishing AIX and HPUX and SunOS and Solaris?  Any ideas?

 
 
 

Testing Unix type (BSD/S5) in shell?

Post by Jahn Rentmeist » Sat, 06 Jan 1996 04:00:00


: And how about distinguishing AIX and HPUX and SunOS and Solaris?  Any ideas?

uname

 
 
 

Testing Unix type (BSD/S5) in shell?

Post by Brendan O D » Tue, 09 Jan 1996 04:00:00





>>I am developing a large body of Korn shell scripts and would like to make
>> ...
>>And how about distinguishing AIX and HPUX and SunOS and Solaris?  Any ideas?

>Something against to use `uname' ?

The output of uname is not particularly well defined - your vendor can
put just about anything there.  As an example, what do these uname -a
outputs tell you?

    OSx512MNI crg1 5.1a-91a010 0630v MIS-4/03
    tyndall2 tyndall2 1.1-94c079 dcosx MIServer-ES 6/320 r3000
    diablo diablo 4.0 2 PENTIUM P5/EISA

The first is a dual-universe pyramid (yeaachhh) which, for scripting
purposes may be treated as either 4.2BSD _or_ SVR3 depending on which
`universe' you are running.

The last two are both SVR4 variants.

So, uname is not always going to help you out.  You might want to look
at the Configure script from patch or perl [metaconfig] to get some
hints.

Alternatively, if you have perl5 installed,

    perl -e 'use Config; print $Config{osname}'

may help (as will rewriting the scripts in perl :-).

The simplest thing to do is create a per machine configuration file
somewhere like /usr/local/etc to cache whatever os-dependant variables
you need (which also saves startup time-your scripts need not go through
a dozen tests every time they are invoked).  An example would be to have
say /usr/local/etc/machdefs contain:

    osname='svr4.0'
    echo='/bin/echo'
    echo_n=''
    echo_c='\c'
    mailer='/usr/ucblib/sendmail'

etc. which then lets you say things like:

    #!/bin/sh

    . /usr/local/etc/machdefs

    $echo $echo_n "An example: cursor here ->$echo_c"

If your echo uses `-n' rather than `\c', you can setup the machdefs
file appropriately:

    echo_n='-n'
    echo_c=''

Regards,
--

Compusol Pty. Limited                   (NSW, Australia)  +61 2 809 0133