Next: , Previous: , 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 unit expression, and type the new units you want. If a units expression contains non-alphanumeric characters, you may need to protect it from interpretation by the shell using single or double 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 (zero) to the calling environment. If you enter non-conformable units then units will print a message giving the reduced form of each unit and it will return failure (nonzero) to the calling environment.

When you invoke units 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.