1

By default, the GNU units command outputs length units in meters. If I want to use a different unit, I have to specify this manually at the You want: prompt. Is there a way to change the default from meters to something else?

$ units
Currency exchange rates from FloatRates (USD base) on 2020-07-08
3496 units, 109 prefixes, 109 nonlinear units

You have: (1gallon)^(1/3)
You want:
        Definition: 0.15584913 m

In the above example, I might want this interaction, with empty You want: input, to produce the output Definition: 0.51131604 ft or Definition: 6 in + 1.0863395 * 1|8 in. At present, I only know how to get these outputs by specifying ft or ftin explicitly:

You have: (1gallon)^(1/3)
You want: ft
        * 0.51131604
        / 1.9557376
You have: (1gallon)^(1/3)
You want: ftin
        6 in + 1.0863395 * 1|8 in

It seems like it should also be possible to configure these as defaults using a command line option like --units, or an environment variable like UNITS_SYSTEM, or an entry in ~/.units.

Metamorphic
  • 1,109
  • 1
  • 10
  • 26

1 Answers1

1

When you press Enter at the “You want:” prompt, you’re not requesting a default unit, you’re requesting the definition of the unit you entered at the “You have:” prompt. That’s why the result starts with “Definition:”.

If you don’t specify a value with the start unit, you’ll see the full definition; thus (with a British locale):

$ units
Currency exchange rates from FloatRates (USD base) on 2020-10-06 
3072 units, 109 prefixes, 109 nonlinear units

You have: gallon
You want:
        Definition: brgallon = 4.54609 l = 0.00454609 m^3
You have: 

If you specify a value, units shows the corresponding value in the non-converting unit based on the definition (i.e. a unit with ! in the equivalence column in the definition.units file), which for length-related units is the metre.

As a result of all this you can’t specify a different default “target” unit, except by rewriting the definitions.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164