Simple Bash Currency Converter

Dmitri Popov

Productivity Sauce

Mar 14, 2013 GMT
Dmitri Popov

Every now and then, I need to convert from one currency to another. Usually, I perform the conversion directly from the address bar in Chromium. It's convenient, but this can only be done using the browser configured to use Google as the default search engine. In my search for a more flexible solution, I stumbled upon a simple and clever trick that makes it possible to perform currency conversion from the command-line. The trick is very simple, indeed: it uses the wget tool to fetch the conversion result and then pipes it to sed for some cleaning. To add this functionality to Bash, open the .bashrc file for editing and add the following function at the end of the file:

cconv() {
  wget -qO- "$1&from=$2&to=$3" |  sed '/res/!d;s/<[^>]*>//g';

In the terminal, type cconv followed by the amount, source currency, and target currency, for example:

11 usd eur

Hit Enter, and you should see the conversion result.


  • great

    this is beautiful. thank you for the idea!
comments powered by Disqus

Issue 203/2017

Buy this issue as a PDF

Digital Issue: Price $9.99
(incl. VAT)