<?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>Personal blog of Chris Ergatides &#187; shell</title>
	<atom:link href="http://blog.ergatides.com/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ergatides.com</link>
	<description>jQuery, Linux, Technology, Web Design and random stuff.</description>
	<lastBuildDate>Mon, 06 Feb 2012 05:01:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Relative path to absolute path in a bash shell.</title>
		<link>http://blog.ergatides.com/2012/01/13/relative-path-to-absolute-path-in-a-bash-shell/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=relative-path-to-absolute-path-in-a-bash-shell</link>
		<comments>http://blog.ergatides.com/2012/01/13/relative-path-to-absolute-path-in-a-bash-shell/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 07:45:13 +0000</pubDate>
		<dc:creator>Chris Ergatides</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[dbpath]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[readlink]]></category>
		<category><![CDATA[realpath]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[skype]]></category>

		<guid isPermaLink="false">http://blog.ergatides.com/?p=1619</guid>


		<description><![CDATA[<p>There are many ways to convert a relative path to an absolute path which can be accessed regardless of the current working directory, particularly useful for scripting. Later, I may make a post to demonstrate the various ways, but the easiest way to do this is to use the <em>readlink</em> utility which comes bundled with just about every Linux distribution with the exception of Debian based systems which use <em>realpath</em> instead.</p>
<pre class="brush: bash; title: ; notranslate">
$ pwd
/media/usbdisk/bin

$ readlink -f ./../mnt/.Skype
/media/usbdisk/mnt/.Skype
</pre>
<p>When you use readlink in a script and assign a resulting path to a variable, you should add the n flag (-fn) to suppress the trailing newline.</p>
<p>As you might have noticed, I needed to use this in a script to launch Skype but specify that I want to use the data files on my usb key as opposed to the default ~/.Skype location. This however was not working with relative paths and Skype would crash with something like:</p>
<blockquote><p>$ FatalAssert(*out_ptr != &#8216;.&#8217; &#038;&#038; !strstr(out_ptr, &#8220;../&#8221;) &#038;&#038; !strstr(out_ptr, &#8220;..\\&#8221;))<br />
FatalAssert(*out_ptr != &#8216;.&#8217; &#038;&#038; !strstr(out_ptr, &#8220;../&#8221;) &#038;&#038; !strstr(out_ptr, &#8220;..\\&#8221;))</p></blockquote>
<p>The moment I pass a real path to Skype&#8217;s &#8211;dbpath parameter, everything works as expected.</p>
<p>Related posts:</p><ol>
<li><a href='http://blog.ergatides.com/2012/01/13/ternary-operator-for-bash-scripting/' rel='bookmark' title='Ternary operator for bash scripting.'>Ternary operator for bash scripting.</a></li>
<li><a href='http://blog.ergatides.com/2011/06/14/automatically-download-and-merge-multiple-pdf-files-with-a-unix-shell/' rel='bookmark' title='Automatically download and merge multiple PDF files with a Unix shell.'>Automatically download and merge multiple PDF files with a Unix shell.</a></li>
<li><a href='http://blog.ergatides.com/2011/11/18/how-to-install-kde-on-fedora-core-13-and-onwards/' rel='bookmark' title='How to install KDE on Fedora Core 13 and onwards.'>How to install KDE on Fedora Core 13 and onwards.</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>There are many ways to convert a relative path to an absolute path which can be accessed regardless of the current working directory, particularly useful for scripting. Later, I may make a post to demonstrate the various ways, but the easiest way to do this is to use the <em>readlink</em> utility which comes bundled with just about every Linux distribution with the exception of Debian based systems which use <em>realpath</em> instead.</p>
<pre class="brush: bash; title: ; notranslate">
$ pwd
/media/usbdisk/bin

$ readlink -f ./../mnt/.Skype
/media/usbdisk/mnt/.Skype
</pre>
<p>When you use readlink in a script and assign a resulting path to a variable, you should add the n flag (-fn) to suppress the trailing newline.</p>
<p>As you might have noticed, I needed to use this in a script to launch Skype but specify that I want to use the data files on my usb key as opposed to the default ~/.Skype location. This however was not working with relative paths and Skype would crash with something like:</p>
<blockquote><p>$ FatalAssert(*out_ptr != &#8216;.&#8217; &#038;&#038; !strstr(out_ptr, &#8220;../&#8221;) &#038;&#038; !strstr(out_ptr, &#8220;..\\&#8221;))<br />
FatalAssert(*out_ptr != &#8216;.&#8217; &#038;&#038; !strstr(out_ptr, &#8220;../&#8221;) &#038;&#038; !strstr(out_ptr, &#8220;..\\&#8221;))</p></blockquote>
<p>The moment I pass a real path to Skype&#8217;s &#8211;dbpath parameter, everything works as expected.</p>
<p>Related posts:</p><ol>
<li><a href='http://blog.ergatides.com/2012/01/13/ternary-operator-for-bash-scripting/' rel='bookmark' title='Ternary operator for bash scripting.'>Ternary operator for bash scripting.</a></li>
<li><a href='http://blog.ergatides.com/2011/06/14/automatically-download-and-merge-multiple-pdf-files-with-a-unix-shell/' rel='bookmark' title='Automatically download and merge multiple PDF files with a Unix shell.'>Automatically download and merge multiple PDF files with a Unix shell.</a></li>
<li><a href='http://blog.ergatides.com/2011/11/18/how-to-install-kde-on-fedora-core-13-and-onwards/' rel='bookmark' title='How to install KDE on Fedora Core 13 and onwards.'>How to install KDE on Fedora Core 13 and onwards.</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://blog.ergatides.com/2012/01/13/relative-path-to-absolute-path-in-a-bash-shell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting back the missed minimize/maximize buttons in GNOME 3.</title>
		<link>http://blog.ergatides.com/2011/06/17/getting-back-the-missed-minimizemaximize-buttons-in-gnome-3/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-back-the-missed-minimizemaximize-buttons-in-gnome-3</link>
		<comments>http://blog.ergatides.com/2011/06/17/getting-back-the-missed-minimizemaximize-buttons-in-gnome-3/#comments</comments>
		<pubDate>Fri, 17 Jun 2011 18:31:01 +0000</pubDate>
		<dc:creator>Chris Ergatides</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[gnome 3]]></category>
		<category><![CDATA[gnome3]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[maximize]]></category>
		<category><![CDATA[minimize]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.ergatides.com/?p=762</guid>


		<description><![CDATA[<p>Struggling to get used to it, I was very much missing the minimize/maximize buttons on my applications in GNOME 3.</p>
<p style="text-align: center;"><img class="size-full wp-image-763 aligncenter" title="gnome3_minmax" src="http://blog.ergatides.com/wp-content/uploads/2011/06/gnome3_minmax.png" alt="gnome3_minmax" width="511" height="128" /></p>
<p>I have finally found a solution to get these buttons back and if you are looking for a solution, this should work for you too:</p>
<ul>
<li>$ <em>sudo yum -y install gnome-tweak-tool</em></li>
<li>$ <em>gnome-tweak-tool</em></li>
<li>Click on <em>Shell</em></li>
<li>Change <strong>Arrangement of buttons on the title bar</strong> from <em>Close only</em> to <em>All</em></li>
<li>Log out or Restart</li>
<li>Log in</li>
<li>Enjoy!</li>
</ul>
<p>Related posts:</p><ol>
<li><a href='http://blog.ergatides.com/2011/06/26/fedora-gnome-3-show-desktop-keyboard-shortcut/' rel='bookmark' title='Fedora GNOME 3 show desktop keyboard shortcut.'>Fedora GNOME 3 show desktop keyboard shortcut.</a></li>
<li><a href='http://blog.ergatides.com/2011/11/18/how-to-install-kde-on-fedora-core-13-and-onwards/' rel='bookmark' title='How to install KDE on Fedora Core 13 and onwards.'>How to install KDE on Fedora Core 13 and onwards.</a></li>
<li><a href='http://blog.ergatides.com/2009/11/30/installing-fedora-core-12-fc12-constantine-on-old-hardware/' rel='bookmark' title='Installing Fedora Core 12 (FC12 &#8220;Constantine&#8221;) on old hardware.'>Installing Fedora Core 12 (FC12 &#8220;Constantine&#8221;) on old hardware.</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Struggling to get used to it, I was very much missing the minimize/maximize buttons on my applications in GNOME 3.</p>
<p style="text-align: center;"><img class="size-full wp-image-763 aligncenter" title="gnome3_minmax" src="http://blog.ergatides.com/wp-content/uploads/2011/06/gnome3_minmax.png" alt="gnome3_minmax" width="511" height="128" /></p>
<p>I have finally found a solution to get these buttons back and if you are looking for a solution, this should work for you too:</p>
<ul>
<li>$ <em>sudo yum -y install gnome-tweak-tool</em></li>
<li>$ <em>gnome-tweak-tool</em></li>
<li>Click on <em>Shell</em></li>
<li>Change <strong>Arrangement of buttons on the title bar</strong> from <em>Close only</em> to <em>All</em></li>
<li>Log out or Restart</li>
<li>Log in</li>
<li>Enjoy!</li>
</ul>
<p>Related posts:</p><ol>
<li><a href='http://blog.ergatides.com/2011/06/26/fedora-gnome-3-show-desktop-keyboard-shortcut/' rel='bookmark' title='Fedora GNOME 3 show desktop keyboard shortcut.'>Fedora GNOME 3 show desktop keyboard shortcut.</a></li>
<li><a href='http://blog.ergatides.com/2011/11/18/how-to-install-kde-on-fedora-core-13-and-onwards/' rel='bookmark' title='How to install KDE on Fedora Core 13 and onwards.'>How to install KDE on Fedora Core 13 and onwards.</a></li>
<li><a href='http://blog.ergatides.com/2009/11/30/installing-fedora-core-12-fc12-constantine-on-old-hardware/' rel='bookmark' title='Installing Fedora Core 12 (FC12 &#8220;Constantine&#8221;) on old hardware.'>Installing Fedora Core 12 (FC12 &#8220;Constantine&#8221;) on old hardware.</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://blog.ergatides.com/2011/06/17/getting-back-the-missed-minimizemaximize-buttons-in-gnome-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Handy command line currency converter.</title>
		<link>http://blog.ergatides.com/2010/02/24/handy-command-line-currency-converter/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=handy-command-line-currency-converter</link>
		<comments>http://blog.ergatides.com/2010/02/24/handy-command-line-currency-converter/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 21:15:18 +0000</pubDate>
		<dc:creator>Chris Ergatides</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.ergatides.com/?p=154</guid>


		<description><![CDATA[<p>In 2003, I wrote a custom Amazon-like shopping cart script. Back then, my web scraping skills weren&#8217;t, ahem, the best they could have been. For the site&#8217;s currency conversions, I had a cron job pull down 3 sets of converstions, calculated the average for each currency pair, then stored the result locally for my use.</p>
<p>At the time, I did this hoping that in a worse-case-scenario, a maximum of 2 sources would die in any weekend. Luckily, the sources lasted for the 3 years whilst I was working for that company (and apparently for another two after that). Now, I hear, they are manually updating a static text file&#8230; once in a while.</p>
<p>Today, I have no such needs but as always I am constantly looking for new ways to do things, should the need arise. I also needed a simple currency converter for doing small calculations like how much to top up a prepaid credit card by to purchase something from eBay which is listed in another currency.</p>
<p>Full credits to <a href="http://commandliners.com/2009/02/currency-conversion-script/">rafacas at commandliners</a> for the inspiration and as he points out, note that the script uses <a href="http://www.google.com/finance">Google Finance’s page</a>.</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash

# 2009 - Rafa Casado - http://bit.ly/bYZwex
# 2010 - Chris Ergatides - http://bit.ly/9XjAUz

if [ $# -lt 2 ]; then
    echo -e &quot;\nUsage: $0 currency1 currency2 amount&quot;
    echo &quot;Default: $0 GBP EUR 1&quot;
    echo &quot;Example 1: $0 USD GBP&quot;
    echo &quot;Example 2: $0 GBP USD 42&quot;
fi

toUpper() {
    echo $@ | tr &quot;[:lower:]&quot; &quot;[:upper:]&quot;
}

if [ -n &quot;$1&quot; ]; then FROM=$(toUpper &quot;$1&quot;); else FROM=GBP; fi
if [ -n &quot;$2&quot; ]; then TO=$(toUpper &quot;$2&quot;); else TO=EUR; fi
if [ $TO == $FROM ]; then echo 'Nothing to do!'; exit 2; fi
if [ -n &quot;$3&quot; ]; then A=$3; else A=1; fi

CONVERTER=&quot;http://www.google.com/finance/converter?a=$A&amp;from=$FROM&amp;to=$TO&quot;

RESULT=`wget -nv -O - &quot;$CONVERTER&quot; 2&gt;&amp;1 | \
sed -n -e 's/.*&lt;span class=bld&gt;\(.*\)&lt;\/span&gt;.*/\1/p'`

echo -e &quot;\nResult: $A $FROM = $RESULT\n&quot;
</pre>
<p>So, let&#8217;s say you&#8217;ve named the script currency.sh and made it executable with chmod +x, what does the output look like?</p>
<pre class="brush: bash; title: ; notranslate">
#Called without any parameters:
[chris@r500 ~/bin]$ ./currency.sh

Usage: /home/chris/bin/currency.sh currency1 currency2 amount
Default: /home/chris/bin/currency.sh GBP EUR 1
Example 1: /home/chris/bin/currency.sh USD GBP
Example 2: /home/chris/bin/currency.sh GBP USD 42

Result: 1 GBP = 1.1387 EUR
</pre>
<pre class="brush: bash; title: ; notranslate">
#Called with example 1's parameters:
[chris@r500 ~/bin]$ ./currency.sh usd gbp

Result: 1 USD = 0.6475 GBP
</pre>
<pre class="brush: bash; title: ; notranslate">
#Called with example 2's parameters
[chris@r500 ~/bin]$ ./currency.sh gbp usd 42

Result: 42 GBP = 64.8606 USD
</pre>
<p>Related posts:</p><ol>
<li><a href='http://blog.ergatides.com/2011/02/21/whats-my-ip-check-your-ip-address-from-the-command-line/' rel='bookmark' title='What&#8217;s my IP? Check your IP address from the command line.'>What&#8217;s my IP? Check your IP address from the command line.</a></li>
<li><a href='http://blog.ergatides.com/2012/01/13/ternary-operator-for-bash-scripting/' rel='bookmark' title='Ternary operator for bash scripting.'>Ternary operator for bash scripting.</a></li>
<li><a href='http://blog.ergatides.com/2012/01/24/using-sed-to-search-and-replace-contents-of-next-line-in-a-file/' rel='bookmark' title='Using sed to search and replace contents of next line in a file.'>Using sed to search and replace contents of next line in a file.</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In 2003, I wrote a custom Amazon-like shopping cart script. Back then, my web scraping skills weren&#8217;t, ahem, the best they could have been. For the site&#8217;s currency conversions, I had a cron job pull down 3 sets of converstions, calculated the average for each currency pair, then stored the result locally for my use.</p>
<p>At the time, I did this hoping that in a worse-case-scenario, a maximum of 2 sources would die in any weekend. Luckily, the sources lasted for the 3 years whilst I was working for that company (and apparently for another two after that). Now, I hear, they are manually updating a static text file&#8230; once in a while.</p>
<p>Today, I have no such needs but as always I am constantly looking for new ways to do things, should the need arise. I also needed a simple currency converter for doing small calculations like how much to top up a prepaid credit card by to purchase something from eBay which is listed in another currency.</p>
<p>Full credits to <a href="http://commandliners.com/2009/02/currency-conversion-script/">rafacas at commandliners</a> for the inspiration and as he points out, note that the script uses <a href="http://www.google.com/finance">Google Finance’s page</a>.</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash

# 2009 - Rafa Casado - http://bit.ly/bYZwex
# 2010 - Chris Ergatides - http://bit.ly/9XjAUz

if [ $# -lt 2 ]; then
    echo -e &quot;\nUsage: $0 currency1 currency2 amount&quot;
    echo &quot;Default: $0 GBP EUR 1&quot;
    echo &quot;Example 1: $0 USD GBP&quot;
    echo &quot;Example 2: $0 GBP USD 42&quot;
fi

toUpper() {
    echo $@ | tr &quot;[:lower:]&quot; &quot;[:upper:]&quot;
}

if [ -n &quot;$1&quot; ]; then FROM=$(toUpper &quot;$1&quot;); else FROM=GBP; fi
if [ -n &quot;$2&quot; ]; then TO=$(toUpper &quot;$2&quot;); else TO=EUR; fi
if [ $TO == $FROM ]; then echo 'Nothing to do!'; exit 2; fi
if [ -n &quot;$3&quot; ]; then A=$3; else A=1; fi

CONVERTER=&quot;http://www.google.com/finance/converter?a=$A&amp;from=$FROM&amp;to=$TO&quot;

RESULT=`wget -nv -O - &quot;$CONVERTER&quot; 2&gt;&amp;1 | \
sed -n -e 's/.*&lt;span class=bld&gt;\(.*\)&lt;\/span&gt;.*/\1/p'`

echo -e &quot;\nResult: $A $FROM = $RESULT\n&quot;
</pre>
<p>So, let&#8217;s say you&#8217;ve named the script currency.sh and made it executable with chmod +x, what does the output look like?</p>
<pre class="brush: bash; title: ; notranslate">
#Called without any parameters:
[chris@r500 ~/bin]$ ./currency.sh

Usage: /home/chris/bin/currency.sh currency1 currency2 amount
Default: /home/chris/bin/currency.sh GBP EUR 1
Example 1: /home/chris/bin/currency.sh USD GBP
Example 2: /home/chris/bin/currency.sh GBP USD 42

Result: 1 GBP = 1.1387 EUR
</pre>
<pre class="brush: bash; title: ; notranslate">
#Called with example 1's parameters:
[chris@r500 ~/bin]$ ./currency.sh usd gbp

Result: 1 USD = 0.6475 GBP
</pre>
<pre class="brush: bash; title: ; notranslate">
#Called with example 2's parameters
[chris@r500 ~/bin]$ ./currency.sh gbp usd 42

Result: 42 GBP = 64.8606 USD
</pre>
<p>Related posts:</p><ol>
<li><a href='http://blog.ergatides.com/2011/02/21/whats-my-ip-check-your-ip-address-from-the-command-line/' rel='bookmark' title='What&#8217;s my IP? Check your IP address from the command line.'>What&#8217;s my IP? Check your IP address from the command line.</a></li>
<li><a href='http://blog.ergatides.com/2012/01/13/ternary-operator-for-bash-scripting/' rel='bookmark' title='Ternary operator for bash scripting.'>Ternary operator for bash scripting.</a></li>
<li><a href='http://blog.ergatides.com/2012/01/24/using-sed-to-search-and-replace-contents-of-next-line-in-a-file/' rel='bookmark' title='Using sed to search and replace contents of next line in a file.'>Using sed to search and replace contents of next line in a file.</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://blog.ergatides.com/2010/02/24/handy-command-line-currency-converter/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

