www.delorie.com/gnu/docs/units/units_3.html   search  
 
Buy GNU books!


Units: A Unit Conversion Program

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3. Using units non-interactively

The units program can perform units conversions non-interactively from the command line. To do this, type the command, type the original units expression, and type the new units you want. You will probably need to protect the units expressions from interpretation by the shell using single quote characters.

If you type

 
    units '2 liters' 'quarts'
then units will print

 
        * 2.1133764
        / 0.47317647
and then exit. The output tells you that 2 liters is about 2.1 quarts, or alternatively that a quart is about 0.47 times 2 liters.

If the conversion is successful, then units will return success (0) to the calling environment. If units is given non-conformable units to convert, it will print a message giving the reduced form of each unit and it will return failure (nonzero) to the calling environment.

When units is invoked with only one argument, it will print out the definition of the specified unit. It will return failure if the unit is not defined and success if the unit is defined.


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003