Previous Table of Contents Next

Module 85
machid (SV)


The external machid commands return a true or false value. Machid is not a command itself but refers to a set of commands. These commands are used to identify the hardware you are using. They are usually used in shell scripts to provide portability. If the machid command you use has a return value of zero (0), you are using the hardware described by the command name. The following example is a typical shell script coding:

if vax # If on a vax computer,
then cd /usr/lib/vax # change directories to vax one
else cd /usr/lib/other # else change dir to other one
fi # end the if conditional.


Following is the general format of each machid command.

pdp11 True if on a DEC PDP-11/45&[tm] or PDP-11/70&[tm] computer.
u3b True if on an AT&T 3B20&[tm] computer.
u3b2 True if on an AT&T 3B2&[tm] computer.
u3b5 True if on an AT&T 3B5&[tm] computer.
u3b15 True if on an AT&T 3B15&[tm] computer.
sun True if on a Sun Microsystems computer.
sun3 True if on a Sun model 3 computer.
sun4 True if on a Sun model 4 (SPARC&[tm]) computer.
vax True if on a DEC VAX-11/750&[tm] or VAX-11/780&[tm] computer.
u370 True if on an IBM System/370&[tm] computer.

Not all vendors implement all of the commands. Usually the vendor only implements the more common hardware types and one for the vendor’s own hardware.


Refer to the test command described in Module 135.


The machid commands do no return output, they simply provide return codes.


The machid commands return a true (zero) value if you are on the type of machine the command describes. If you are NOT on the machine described by the command name, then a false (nonzero) value is returned.


These commands are used in shell scripts to provide portability across different types of hardware. Shell scripts can be coded to handle different hardware device paths, different command formats, and various other system dependencies. The machid commands are useful in a make file to control how a program is compiled. In some cases the uname command, described in Module 148, can be used to perform the same task. If uname is used, the test command must be used to check for specific strings being returned.


In this activity you use the machid commands to display what type of system you are using. Begin at the shell prompt.

1.  Type in the following code at your shell prompt. As you enter new lines your secondary prompt (PS2) will be displayed. You may wish to use the whence command to see if your system supports any of the commands used in this activity.
     cj> for CMDTYPE in u3b2 u3b5 vax
      if $CMDTYPE
      then echo You are using a $CMDTYPE machine!

You may wish to add additional hardware names on the for line.
2.  Turn to Module 144 to continue the learning sequence.

Previous Table of Contents Next