8 Invoking units
You invoke units like this:
units [options] [from-unit [to-unit]]
If the from-unit and to-unit are omitted, then the program
will use interactive prompts to determine which conversions to perform.
See Interactive Use.
If both from-unit and to-unit are given, units will
print the result of that single conversion and then exit.
If only from-unit appears on the command line, units will
display the definition of that unit and exit.
Units specified on the command line may need
to be quoted to protect them from shell interpretation and to group
them into two arguments. See Command Line Use.
The following options allow you to read in an alternative units file,
check your units file, or change the output format:
- -c
- --check
- Check that all units and prefixes defined in the units data file reduce
to primitive units. Print a list of all units that
cannot be reduced. Also display some other diagnostics about
suspicious definitions in the units data file. Only definitions active
in the current locale are checked. You should always run
units with this option after modifying a units data file.
- --check-verbose
- Like the --check option, this option prints a list of units that
cannot be reduced. But to help find unit definitions that cause
endless loops,
it lists the units as they are checked.
If units hangs, then the last unit to be printed has a bad
definition. Only definitions active in the current locale are checked.
- -o format
- --output-format format
- Use the specified format for numeric output; the format is a
subset of that for the printf function in the ANSI C standard. Only a
numeric format (‘E’ or ‘e’ for scientific notation, ‘f’
for fixed-point decimal, or ‘G’ or ‘g’ to specify the number
of significant figures) is allowed. The default format is ‘%.8g’;
for greater precision, you could specify ‘-o %.15g’.
See Numeric Output Format, and the documentation for printf() for more
detailed descriptions of the format specification.
- -e
- --exponential
- Set the numeric output format to exponential (i.e., scientific
notation), like that used in the Unix units program.
- -f filename
- --file filename
- Instruct units to load the units file
filename. You
can specify up to 25 units files on the command line. When you use
this option, units will load only the files you list
on the command line; it will not load the standard file or your
personal units file unless you explicitly list them. If filename
is the empty string (‘-f ""’), the default units file (or that
specified by UNITSFILE) will be loaded in addition to any others
specified with ‘-f’.
- -h
- --help
- Print out a summary of the options for units.
- -m
- --minus
- Causes ‘-’ to be interpreted as a subtraction operator. This is
the default behavior.
- -p
- --product
- Causes ‘-’ to be interpreted as a multiplication operator when it
has two operands. It will act as a negation operator when it has only one
operand: ‘(-3)’. By default ‘-’ is treated as a
subtraction operator.
- --oldstar
- Causes ‘*’ to have the old-style precedence, higher than the
precedence of division so that ‘1/2*3’ will equal ‘1/6’.
- --newstar
- Forces ‘*’ to have the new (default) precedence that follows
the usual rules of algebra: the precedence of ‘*’ is the same as
the precedence of ‘/’, so that ‘1/2*3’ will equal ‘3/2’.
- --compact
- Give compact output featuring only the conversion factor. This turns
off the --verbose option.
- -q
- --quiet
- --silent
- Suppress prompting of the user for units and the display of statistics
about the number of units loaded.
- -n
- --nolists
- Disable conversion to unit lists.
- -r
- --round
- When converting to a combination of units given by a unit list, round
the value of the last unit in the list to the nearest integer.
- -S
- --show-factor
- When converting to a combination of units specified in a list,
always show a non-unity factor before a unit that
begins with a fraction with a unity denominator. By default, if the
unit in a list begins with fraction of the form 1|x and
its multiplier is an integer other than 1, the fraction is given as the
product of the multiplier and the numerator (e.g., ‘3|8 in’ rather
than ‘3 * 1|8 in’). In some cases, this is not what is wanted;
for example, the results for a cooking recipe might show
‘3 * 1|2 cup’ as ‘3|2 cup’.
With the --show-factor option, a
result equivalent to 1.5 cups will display as ‘3 * 1|2 cup’ rather
than ‘3|2 cup’. A user-specified fractional unit with a numerator
other than 1 is never overridden, however—if a unit list specifies
‘3|4 cup;1|2 cup’, a result equivalent to 1 1/2 cups will
always be shown as ‘2 * 3|4 cup’ whether or not the
--show-factor option is given.
- -s
- --strict
- Suppress conversion of units to their reciprocal units. For
example, units will normally convert hertz to seconds
because these units are reciprocals of each other. The strict option
requires that units be strictly conformable to perform a conversion, and
will give an error if you attempt to convert hertz to seconds.
- -1
- --one-line
- Give only one line of output (the forward conversion). Do not print
the reverse conversion. If a reciprocal conversion is
performed then units will still print the “reciprocal
conversion” line.
- -t
- --terse
- Give terse output when converting units. This option can be used when
calling units from another program so that the output is easy to
parse. This option has the combined
effect of these options: --strict --quiet --one-line
--compact.
- -v
- --verbose
- Give slightly more verbose output when converting units. When combined
with the -c option this gives the same effect as
--check-verbose.
- -V
- --version
- Print program version number, tell whether the readline
library has been included, and give the location of the default units
data file.
- -l locale
- --locale locale
- Force a specified locale such as ‘en_GB’ to get British
definitions by default. This overrides the locale determined from
system settings or environment variables.
See Locale, for a description of locale format.