<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tools &#8211; Luxing Huang</title>
	<atom:link href="https://luxing.im/tag/tools/feed/" rel="self" type="application/rss+xml" />
	<link>https://luxing.im</link>
	<description>Thoughs and things</description>
	<lastBuildDate>Fri, 21 Feb 2020 20:43:01 +0000</lastBuildDate>
	<language>en-CA</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
<site xmlns="com-wordpress:feed-additions:1">58771605</site>	<item>
		<title>Currency Conversion on Bash</title>
		<link>https://luxing.im/currency-conversion-on-bash/</link>
					<comments>https://luxing.im/currency-conversion-on-bash/#comments</comments>
		
		<dc:creator><![CDATA[Luxing Huang]]></dc:creator>
		<pubDate>Tue, 06 Nov 2018 20:11:48 +0000</pubDate>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Techie Stuff]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[currency]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[tools]]></category>
		<guid isPermaLink="false">https://luxing.im/?p=770</guid>

					<description><![CDATA[Currency.sh I had an idea long ago to convert currency on bash. So first you need a live currency conversion API in order to get a most up-to-date conversion rate data, preferably free. After searching through the internet, this one is a good API. I&#8217;ve been using it for some time and normally it is &#8230; <p class="link-more"><a href="https://luxing.im/currency-conversion-on-bash/" class="more-link">Continue reading<span class="screen-reader-text"> "Currency Conversion on Bash"</span></a></p>]]></description>
										<content:encoded><![CDATA[<p><a href="https://luxing.im/wp-content/uploads/2018/11/currency.png"><img decoding="async" src="https://luxing.im/wp-content/uploads/2018/11/currency-300x108.png" alt="" width="300" height="108" class="alignleft size-medium wp-image-771" srcset="https://luxing.im/wp-content/uploads/2018/11/currency-300x108.png 300w, https://luxing.im/wp-content/uploads/2018/11/currency.png 343w" sizes="(max-width: 300px) 100vw, 300px" /></a> Currency.sh<br />
<span id="more-770"></span></p>
<p>I had an idea long ago to convert currency on bash.</p>
<p>So first you need a live currency conversion API in order to get a most up-to-date conversion rate data, preferably free. After searching through the internet, <a href="https://free.currencyconverterapi.com/" rel="noopener noreferrer" target="_blank">this one</a> is a good API. I&#8217;ve been using it for some time and normally it is quite stable.</p>
<p>The only dependency you need to install is jq, please use your package manager to install.</p>
<p>Usage:</p>
<pre>currency.sh <currency1> <currency2> [quantity]</pre>
<p>You currency code must meet <a href="https://en.wikipedia.org/wiki/ISO_4217" rel="noopener noreferrer" target="_blank">ISO 4217</a> standard.</p>
<p>Script:</p>
<pre>
#!/bin/bash
jq 2> /dev/null
if [ "$?" != 2 ]; then
  echo "Please install jq"
  exit 1
fi

if [ -z "$1" -o -z "$2" ]; then
  echo "Please provide first and second currency."
  echo "e.g. $0 CAD USD [amount]"
  exit 1
fi

currency1=`echo -n $1 | tr '[:lower:]' '[:upper:]'`
currency2=`echo -n $2 | tr '[:lower:]' '[:upper:]'`

unit_price_f=$(curl -s "https://free.currencyconverterapi.com/api/v5/convert?q=${currency1}_${currency2}&compact=y" | jq ".${currency1}_${currency2}.val")

unit_price=$(printf "%.8f" $unit_price_f)

echo Unit price buy $1 from $2 is $unit_price.

if [ ! -z "$3" ]; then
  echo
  echo -n "$3 $1 is "
  echo "$3 * $unit_price" | bc -l | tr -d "\n"
  echo " $2"
fi
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://luxing.im/currency-conversion-on-bash/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">770</post-id>	</item>
	</channel>
</rss>
