Friday, January 17, 2014

Updating Unit's flat file With a One-ish Line Shell Command

After seeing this reddit post relating to a buttload being an actual medieval unit of measurement, I decided that I would update the units database on my machine. Here is the simple command that I came up with:

LOC=$(units -V | grep -o "[/a-z/]*\.dat"); echo "buttload winebutt" | sudo tee -a $LOC

It's simple enough, we get the location of the flat file database from the command's version output flag -v, then grep it to contain only the file name. Then, enter the new unit followed by a reference to an old unit. My up to date units database already had a winebutt defined, so I added the reference.

To add another unit, such as Schrute Bucks to Stanley Nickels we would say:

LOC=$(units -V | grep -o "[/a-z/]*\.dat"); echo "schrutebuck 50 stanleynickels" | sudo tee -a $LOC

No comments:

Post a Comment