Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Am I missing something?' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Am I missing something?
Authored by: babbage on Jun 01, '01 04:17:35PM
Hmm. Well, in the Unix spirit of things, maybe this is just meant to serve as a filter for other programs. Given a pair of input units, you can get it to produce regular, machine readable output:
4:05:12pm :chris% units feet meters
        * 0.3048
        / 3.2808399
4:05:22pm :chris% units years seconds
        * 31556926
        / 3.1688765e-08
4:05:30pm :chris% units liters gallons
        * 0.26417205
        / 3.7854118
4:05:49pm :chris%
Maybe you could mess around with those result lines to do a conversion. For example, something like: "units [from] [to] | head -1" gives you your mathematical operator (whichever of multiplication or division, and the number to calculate against). You could then embed this within "printf" or (more flexibly) some Sed, Awk, or Perl code.

In any event, I think you're right -- this doesn't seem to be an all-purpose tool for making conversions so much as the raw engine for one, but like an engine with no wheels, that's not very useful without quite a bit of extra work. Too bad.

On the brighter side, if you *do* want to extend it, it looks like you can add more conversions to the data file: /usr/share/misc/units.lib. I don't totally understand the format, but it looks like you should be able to go in (as root) and add, if nothing else, the values for fahrenheit & celcius conversions. Considering a lot of the other ones in there (e.g. kelvin), I'm surprised that those two were left out. Maybe it's the proverbial "exercise left to the reader".....

[ Reply to This | # ]