<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Jacobo de Vera's Weblog</title>
	
	<link>http://blog.jacobodevera.com</link>
	<description>On Technology, Programming, Internet and more</description>
	<lastBuildDate>Sat, 30 Jan 2010 11:09:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/JacoboDeVeraWeblog" /><feedburner:info uri="jacobodeveraweblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>My On-line Identity</title>
		<link>http://feedproxy.google.com/~r/JacoboDeVeraWeblog/~3/DR59yLyr4pM/my-on-line-identity.html</link>
		<comments>http://blog.jacobodevera.com/2010/01/30/my-on-line-identity.html#comments</comments>
		<pubDate>Sat, 30 Jan 2010 11:09:48 +0000</pubDate>
		<dc:creator>Jacobo de Vera</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[privacy]]></category>

		<guid isPermaLink="false">http://blog.jacobodevera.com/?p=125</guid>
		<description><![CDATA[I am writing this article as a means to give some order to my thoughts on my on-line identity, specially on how I could take better care of it.
The Past
 Some ten years ago, when I started to have some activity on the Internet, I had some concerns about my privacy and rarely used my [...]]]></description>
			<content:encoded><![CDATA[<p>I am writing this article as a means to give some order to my thoughts on my on-line identity, specially on how I could take better care of it.</p>
<h3>The Past</h3>
<p><img src="http://blog.jacobodevera.com/wp-content/uploads/2010/01/online_identity_qr-150x150.jpg" alt="QR code for this blog" title="My Blog QR" width="150" height="150" class="size-thumbnail wp-image-139" style="float:right; left-padding:10px"/> Some ten years ago, when I started to have some activity on the Internet, I had some concerns about my privacy and rarely used my real name for anything I did on-line. In 2002, I started my own personal blog called Jovian Storm and I used to sign my posts as Jake. Since Jake is a very common name, it was very difficult to associate it to me in any way, except for those who knew me personally, which were the main consumers of my writings (aren&#8217;t they still?). Not long after that, I started to sign up for a number of web apps and on-line communities and used jovianjake as my new user name or nickname.</p>
<p>On the other hand, I had also used other user names that pointed directly to my name, e.g. jacobodevera, for some web apps that I considered more &#8220;serious&#8221;. The thought behind that was that most of those already had my name and I was trying to keep jovianjake and his on-line activity separated from my real self. </p>
<p>When I started to be aware of the concept of on-line identity, how it could affect my reputation and how I could benefit from it just by taking some care of it, I had already been producing content as jovianjake for a while. A quick Google search for my name showed nothing interesting. Most of the results came from official publications by the Spanish Government regarding scholarships, and from people I had traded bootlegs with. </p>
<p>I wanted to change that, so I could be associated to some of the contents I was producing (or consuming). A quick and easy first step was to provide my real name to some of those apps where I had signed up as jovianjake. I also mentioned my name in the About section of my blog. The change in the search results was quick; apparently the Spanish Government publications are not so popular after all (go figure!). This move had a drawback, though: by providing my real name in these sites, I was mapping it to my nickname jovianjake, and privacy was gone for good. </p>
<h3>The Present</h3>
<p>I have kept this scheme for a number of years now but the truth is it does not work very well for me. My on-line identity is now scattered across a variety of user names and nicknames and there is no clear separation between personal, professional, private and public. This is happening because I never had a strategy, not even when I realised I should take care of how the Internet sees me. So what user name to choose depended solely on a punctual decision taken at the moment of signing up. </p>
<p>Strategy is the key word here. I should have created one the moment I realised something was wrong. If I had done that in due time, it wouldn&#8217;t have been that hard to go back and get rid of all things jovianjake that were already public and start producing as jacobodevera or similar. But that is something I can&#8217;t do any more, since I am not willing to let go of all of jovianjake&#8217;s content and the time it would take to reproduce it as somebody else (when possible) makes the effort worthless. </p>
<p>So the plan is coming up with an on-line identity management strategy that has, to a reasonable extent, backwards compatibility with the poor decisions I made in the past. It certainly does not sound great, but it is better than having no strategy at all. </p>
<h3>The Future</h3>
<p>Here comes my shiny new strategy to manage my identity on-line:</p>
<h4>Public stuff</h4>
<p>This sentence is for you to recover from the fact that I used the word &#8220;stuff&#8221; in my strategy.</p>
<p>In those web apps where I don&#8217;t actually mind if the world knows who I am, I will continue using jovianjake as my user name or nickname. Then, if possible, I will include my name in whatever profile information there is available. This will create a clear mapping between this user name and my real name. </p>
<h4>Private Stuff</h4>
<p>In all new accounts that I create from now on in web apps where I don&#8217;t want to make obvious who I am, I will use a different user name or nickname that, of course, I will not mention here. I could even use a different user name for each app (I would love to read your thoughts on this). </p>
<p>There are some web apps or online communities where I had signed up as jovianjake as a privacy measure, to keep them separate from my real self. For those cases, if I want to continue using said app, I will create a new account with a different user name and then will try to move everything into this new account. </p>
<p>However, if by moving data over to a new account I am forced to create any kind of relation between jovianjake and my new user name, I will skip this step and simply start clean slated. It would be nice if I could back up and then delete all of jovianjake&#8217;s contents in that particular app too. </p>
<img src="http://feeds.feedburner.com/~r/JacoboDeVeraWeblog/~4/DR59yLyr4pM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jacobodevera.com/2010/01/30/my-on-line-identity.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.jacobodevera.com/2010/01/30/my-on-line-identity.html</feedburner:origLink></item>
		<item>
		<title>jQuery Snippet: ISBN beside book title in Amazon</title>
		<link>http://feedproxy.google.com/~r/JacoboDeVeraWeblog/~3/fGKeOrTZe-Y/jquery-snippet-isbn-beside-book-title-in-amazon.html</link>
		<comments>http://blog.jacobodevera.com/2009/12/10/jquery-snippet-isbn-beside-book-title-in-amazon.html#comments</comments>
		<pubDate>Thu, 10 Dec 2009 22:29:24 +0000</pubDate>
		<dc:creator>Jacobo de Vera</dc:creator>
				<category><![CDATA[Asides]]></category>

		<guid isPermaLink="false">http://blog.jacobodevera.com/?p=114</guid>
		<description><![CDATA[I often use Amazon to find the ISBN of a book, and it always annoys me (slightly) that I have to scroll down and scan the page looking for this number. So today I put in practice again my recently acquired basic knowledge of jQuery and wrote this snippet that places the ISBN, in square [...]]]></description>
			<content:encoded><![CDATA[<p>I often use <a href="http://www.amazon.co.uk/gp/redirect.html?ie=UTF8&#038;location=http%3A%2F%2Fwww.amazon.co.uk%2F&#038;tag=jacdeversweb-21&#038;linkCode=ur2&#038;camp=1634&#038;creative=19450">Amazon</a> to find the ISBN of a book, and it always annoys me (slightly) that I have to scroll down and scan the page looking for this number. So today I put in practice again my recently acquired basic knowledge of <a href="http://jquery.com/">jQuery</a> and wrote this snippet that places the ISBN, in square brackets, right beside the book title.</p>
<div class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:500px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> isbn10 <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div.content li:contains(ISBN-10)&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;h1.parseasinTitle&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot; [&quot;</span> <span style="color: #339933;">+</span> isbn10 <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>And here is the corresponding bookmarklet:</p>
<p><a href="javascript:var%20s=document.createElement('script');s.setAttribute('src','http://jquery.com/src/jquery-latest.js');document.body.appendChild(s);s.onload=function(){var%20isbn10=$('div.content%20li:contains(ISBN-10)').text().split('%20')[1];$('h1.parseasinTitle').append('%20['+isbn10+']');};void(s);">Amazon ISBN beside title</a></p>
<img src="http://feeds.feedburner.com/~r/JacoboDeVeraWeblog/~4/fGKeOrTZe-Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jacobodevera.com/2009/12/10/jquery-snippet-isbn-beside-book-title-in-amazon.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.jacobodevera.com/2009/12/10/jquery-snippet-isbn-beside-book-title-in-amazon.html</feedburner:origLink></item>
		<item>
		<title>See Only Private Bookmarks On Delicious</title>
		<link>http://feedproxy.google.com/~r/JacoboDeVeraWeblog/~3/fW49DlJW8rw/see-only-private-bookmarks-on-delicious.html</link>
		<comments>http://blog.jacobodevera.com/2009/12/06/see-only-private-bookmarks-on-delicious.html#comments</comments>
		<pubDate>Sun, 06 Dec 2009 17:46:59 +0000</pubDate>
		<dc:creator>Jacobo de Vera</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[delicious]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://blog.jacobodevera.com/?p=98</guid>
		<description><![CDATA[I have only started experimenting with jQuery and I already love it. It was this video/tutorial in John Resig&#8217;s blog that got me started. He has a bookmarklet that brings the jQuery library to any webpage and then uses Firebug to hack the page using the recently embedded jQuery functionality. Once he is happy with [...]]]></description>
			<content:encoded><![CDATA[<p>I have only started experimenting with <a href="http://jquery.com/">jQuery</a> and I already love it. It was <a href="http://ejohn.org/blog/hacking-digg-with-firebug-and-jquery/">this video/tutorial in John Resig&#8217;s blog</a> that got me started. He has a bookmarklet that brings the jQuery library to any webpage and then uses <a href="http://getfirebug.com/">Firebug</a> to hack the page using the recently embedded jQuery functionality. Once he is happy with his hack, he can add the code to the bookmarklet itself and load it all together with a single click.</p>
<p>I followed this approach to solve a long-standing annoyance of <a href="http://delicious.com/">Delicious</a>: The lack of a option to show only the bookmarks that I have marked as private.</p>
<p>Tuns out that with only so much as this little piece of code:</p>
<div class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:500px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul.bookmarks li.post:not(.isPrivate)&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>I can make all the public bookmarks disappear and appear again. Here is a bookmarklet to do that (to use it, simply drag it to your browser&#8217;s toolbar):</p>
<p><a href="javascript:var%20s=document.createElement('script');s.setAttribute('src','http://jquery.com/src/jquery-latest.js');document.body.appendChild(s);s.onload=function(){$('ul.bookmarks%20li.post:not(.isPrivate)').toggle();};void(s);">[Toggle Public Bookmarks]</a></p>
<p>I also noticed that Delicious only places the date on the first bookmark for a particular day, which means that if the bookmark that holds the date is a public one and we hide it, any private bookmark from the same day will be left dateless, thus appearing to have been saved on the latest shown date.</p>
<p><img src="http://blog.jacobodevera.com/wp-content/uploads/2009/12/delicious_date_on_bookmarks.jpg" alt="Dates on Delicious bookmarks" title="Dates on Delicious bookmarks" width="243" height="177" class="aligncenter size-full wp-image-103" /></p>
<p>Fixing this made the code a little bit more complex and since I am not particularly fond of bookmarklets anyway, I decided to make it a <a href="https://addons.mozilla.org/firefox/addon/748">GreaseMonkey</a> Script.</p>
<p>I have uploaded the script to <a href="http://userscripts.org/">Userscripts.org</a> although I am also keeping a local copy, so you can either</p>
<ul>
<li>See <a href="http://userscripts.org/scripts/show/63594">Delicious.com Private Bookmarks Only</a> on Userscripts, or</li>
<li>Install <a href='http://blog.jacobodevera.com/wp-content/uploads/2009/12/delicious_private_only.user.js'>Delicious.com Private Bookmarks Only</a> from the local copy.</li>
</ul>
<p>Once installed, you will see two new links on the header of your Delicious bookmarks page: &#8220;Show only private bookmarks&#8221; and &#8220;Show public &#038; private bookmarks&#8221;</p>
<p><img src="http://blog.jacobodevera.com/wp-content/uploads/2009/12/delicious_private_links_filters.jpg" alt="New links added by the script" title="New links added by the script" width="472" height="100" class="aligncenter size-full wp-image-101" /></p>
<img src="http://feeds.feedburner.com/~r/JacoboDeVeraWeblog/~4/fW49DlJW8rw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jacobodevera.com/2009/12/06/see-only-private-bookmarks-on-delicious.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.jacobodevera.com/2009/12/06/see-only-private-bookmarks-on-delicious.html</feedburner:origLink></item>
		<item>
		<title>GNOME Network Manager Applet With Multiple Users</title>
		<link>http://feedproxy.google.com/~r/JacoboDeVeraWeblog/~3/rbjTwAjzwpg/gnome-network-manager-applet-with-multiple-users.html</link>
		<comments>http://blog.jacobodevera.com/2009/07/30/gnome-network-manager-applet-with-multiple-users.html#comments</comments>
		<pubDate>Thu, 30 Jul 2009 00:01:55 +0000</pubDate>
		<dc:creator>Jacobo de Vera</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.jacobodevera.com/?p=65</guid>
		<description><![CDATA[GNOME&#8217;s Network Manager Applet has a particularly annoying bug/feature: Only one instance can be running at a particular time. This is a problem when several users have sessions opened at a time, by using the fast user switch feature. It looks like this is annoying a lot of people out there, as you can see [...]]]></description>
			<content:encoded><![CDATA[<p><em>GNOME&#8217;s Network Manager Applet</em> has a particularly annoying bug/feature: Only one instance can be running at a particular time. This is a problem when several users have sessions opened at a time, by using the fast user switch feature. It looks like this is annoying a lot of people out there, as you can see from the comments in the <a href="https://bugs.launchpad.net/fedora/+source/network-manager/+bug/284596" title="Bug report for nm-applet">bug report</a>.</p>
<p>Precisely in those comments you can see the two scenarios why this bug can annoy you and even upset you:</p>
<p>Scenario 1, as described in <a href="https://bugs.launchpad.net/fedora/+source/network-manager/+bug/284596/comments/11" title="Comment 11 of the bug report" >comment 11</a> (annoying):</p>
<blockquote><ol>
<li>First user logs into PC, network manager starts up and connects to network</li>
<li>Second user uses fast-user-switcher to logon, has no icon for network manager</li>
<li>Some time later the first user switches back on, and logs out of their account</li>
<li>Now, the second user has no network manager, and the network connection is lost. They&#8217;ve got no way of re-connecting to the network, save manually starting nm or logging out and logging back on.</li>
</ol>
</blockquote>
<p>Scenario 2, as described in <a href="https://bugs.launchpad.net/fedora/+source/network-manager/+bug/284596/comments/12" title="Comment 12 of the bug report" >comment 12</a> (upsetting): </p>
<blockquote><ol>
<li>User A logs into the machine and connects to network</li>
<li>User B logs into the machine</li>
<li>User A or user B puts the machine to sleep</li>
<li>User B wakes the machine but can no longer connect to the network, user A has to log in for this to work.</li>
</ol>
</blockquote>
<p>I would normally understand that, from a security point of view, a connection started by one user should not be allowed to be changed by another. However, there are some environments where this kind of security is not the main goal. I want all the users in my machine to be able to use the Internet even if I leave my session opened before going to work.</p>
<p>So I conveniently disregarded this security issue and created a workaround to temporarily alleviate the consequences of the bug. This doesn&#8217;t solve scenario 1 completely, but at least your users won&#8217;t get trapped in scenario 2.</p>
<p>The first solution I thought of, and the one I originally described in this entry, involved writing a small C program with a calle to one of the exec functions, compiling it and seting the user ID bit so that it would be executed as root. This seemed OK except for the fact that it required compiling a C program. <a href="http://www.ruyk.com/tech" title="Ruyk's tech">Ruyk</a> suggested a better alternative that involved no C at all. This is the one I will describe now.</p>
<p>This is what I did: Give all my users the power to kill the <em>Gnome Network Manager Applet</em> without having to allow them to run <em>sudo</em> (at least not without control) on my machine. After this, they can run the applet again and they will have access to the network.</p>
<p>I did this by editing the file <kbd>/etc/sudoers</kbd> by running:</p>
<pre>
sudo visudo
</pre>
<p>I added this to the end:</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:500px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">%users ALL=NOPASSWD:/usr/bin/killall nm-applet</div></div>
<p>This will allow all users who belong to the group called <em>users</em> to run <kbd>/usr/bin/killall nm-applet</kbd> with sudo without being asked for a password. This means that killall will be executed as root, so my other users could kill the nm-applet instance that I have started). Of course, I need to add those users to the <em>users</em> group, I did so by running this for each user name:</p>
<pre>
usermod -a -G users <em>&lt;username&gt;</em>
</pre>
<p>But I wanted to make life easier for my users, so I wrote this script that kills any running network manager applet and starts a new one in the current session:</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:500px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">killall</span> nm-applet &nbsp;<span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null 2<span style="color: #000000; font-weight: bold;">&gt;&amp;</span>1<br />
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>nm-applet <span style="color: #660033;">--sm-disable</span> &nbsp;<span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span></div></div>
<p>I saved it in a file called <kbd>nm-force</kbd>, copied it to <kbd>/usr/local/bin</kbd>, made root the owner and allowed everyone to run it:</p>
<pre>
sudo cp nm-force /usr/local/bin/nm-force
sudo chown root.root /usr/local/bin/nm-force
sudo chmod 0755 /usr/local/bin/nm-force
</pre>
<p>After all this, you can reproduce scenario 2 and all user B has to do is to hit <em>ALT+F2</em>, type <strong>nm-force</strong>, and hit Enter. <em>User A</em> won&#8217;t have the applet when she logs back in later, but she can do the same as <em>user B</em> to get the applet back. You can also create a launcher for <kbd>nm-force</kbd> to make things simpler for your users.</p>
<p>Don&#8217;t forget to delete those two files when the bug gets fixed!</p>
<img src="http://feeds.feedburner.com/~r/JacoboDeVeraWeblog/~4/rbjTwAjzwpg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jacobodevera.com/2009/07/30/gnome-network-manager-applet-with-multiple-users.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.jacobodevera.com/2009/07/30/gnome-network-manager-applet-with-multiple-users.html</feedburner:origLink></item>
		<item>
		<title>How to escape single quotes in Sed one-liners</title>
		<link>http://feedproxy.google.com/~r/JacoboDeVeraWeblog/~3/A6zKvExsu_Q/how-to-escape-single-quotes-in-sed-one-liners.html</link>
		<comments>http://blog.jacobodevera.com/2009/04/10/how-to-escape-single-quotes-in-sed-one-liners.html#comments</comments>
		<pubDate>Fri, 10 Apr 2009 20:06:29 +0000</pubDate>
		<dc:creator>Jacobo de Vera</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[one-liner]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://blog.jacobodevera.com/?p=60</guid>
		<description><![CDATA[A few days ago, a co-worker came to me with a Sed question. He had a line like this in a file called myfile:

MYVAR='MYVALUE'

He needed to get MYVALUE (without the single quotes around it) into a shell variable and he wanted to use a Sed one-liner.
After a few failed attempts on escaping the single quotes, [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, a co-worker came to me with a Sed question. He had a line like this in a file called <em>myfile</em>:</p>
<pre>
MYVAR='MYVALUE'
</pre>
<p>He needed to get <em>MYVALUE</em> (without the single quotes around it) into a shell variable and he wanted to use a Sed one-liner.</p>
<p>After a few failed attempts on escaping the single quotes, I decided to wrap the Sed expression with double quotes and it worked for me:</p>
<pre>
$ sed "s/^MYVAR='\(.*\)'\$/\1/" myfile
MYVALUE
</pre>
<p>Unfortunately, this did not work for him for some reason that perhaps was related to the fact that he was working in <a href="http://en.wikipedia.org/wiki/AIX_operating_system" title="IBM AIX in Wikipedia">AIX</a>. This alternative method, however, worked for both of us:</p>
<pre>
$ sed 's/^MYVAR='\''\(.*\)'\''$/\1/' myfile
MYVALUE
</pre>
<p>After this, assigning this value to a shell variable is as easy as capturing the output using back ticks:</p>
<pre>
$ SHELLVAR=`sed 's/^MYVAR='\''\(.*\)'\''$/\1/' myfile`
$ echo $SHELLVAR
MYVALUE
</pre>
<img src="http://feeds.feedburner.com/~r/JacoboDeVeraWeblog/~4/A6zKvExsu_Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jacobodevera.com/2009/04/10/how-to-escape-single-quotes-in-sed-one-liners.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.jacobodevera.com/2009/04/10/how-to-escape-single-quotes-in-sed-one-liners.html</feedburner:origLink></item>
		<item>
		<title>Split strings and join lists using Bash</title>
		<link>http://feedproxy.google.com/~r/JacoboDeVeraWeblog/~3/Vpv6ZmvB01s/split-strings-and-join-lists-using-bash.html</link>
		<comments>http://blog.jacobodevera.com/2009/03/10/split-strings-and-join-lists-using-bash.html#comments</comments>
		<pubDate>Tue, 10 Mar 2009 15:19:32 +0000</pubDate>
		<dc:creator>Jacobo de Vera</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://blog.jacobodevera.com/?p=52</guid>
		<description><![CDATA[This weekend I wrote some more Bash functions for my .bashrc file that I thought were worth sharing. The idea came after trying to do a similar thing while writing my addtopath function.
The first one is mysplit, which is not much more than a Bash wrapper for a short Awk script. It takes the contents [...]]]></description>
			<content:encoded><![CDATA[<p>This weekend I wrote some more Bash functions for my <em>.bashrc</em> file that I thought were worth sharing. The idea came after trying to do a similar thing while writing <a href="http://blog.jacobodevera.com/2009/02/21/adding-directories-to-the-path-in-bash.html" title="Adding directories to the PATH in Bash">my <em>addtopath</em> function</a>.</p>
<p>The first one is <em>mysplit</em>, which is not much more than a Bash wrapper for a short Awk script. It takes the contents of a file or a string from standard input (so that another program&#8217;s output can be piped to it) and splits it in separate lines. It uses a user provided string as a delimiter. Actually, this delimiter is treated as an Awk-compatible regular expression, which only makes this even more powerful.</p>
<p>I am changing Awk&#8217;s field delimiter, and then in each line fed to the script, iterate through all the fields and print each on of them in a line of its own.</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:500px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> mysplit<br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">DEFAULT_DELIMITER</span>=<span style="color: #ff0000;">&quot; &quot;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #007800;">delimiter</span>=<span style="color: #800000;">${1:-$DEFAULT_DELIMITER}</span><br />
&nbsp; &nbsp; <span style="color: #007800;">inputfile</span>=$2<br />
<br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$delimiter</span>&quot;</span> \<br />
&nbsp; &nbsp; <span style="color: #ff0000;">'{ &nbsp;for(i = 1; i &lt;= NF; i++) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print $i<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }'</span> <span style="color: #007800;">$inputfile</span><br />
<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #007800;">$?</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span></div></div>
<p>Of course, if there is a <em>mysplit</em>, there has to be a <em>myjoin</em>. And here it is indeed. This function does exactly the opposite of <em>mysplit</em>. It takes several lines from a file or from <em>stdin</em> and turns them into a string, using a user provided delimiter as &#8220;glue&#8221;.</p>
<p>Here I use an Awk/Sed combination (you have to love those two once you get to know them a bit). With Awk, I&#8217;ve changed its ORS (Output Record Separator) from the default new line character to whatever the user wants as delimiter and then simply print everything. There are two problems with this: Awk will print the delimiter also after the last record and, if this delimiter does not contain a new line feed, none will be printed at the end. We need a new line at the end in order to have an output that we can pipe to other programs, as we will see in the examples below. Enter Sed, which I&#8217;ve used to replace the last delimiter with a new line character. Problem solved:</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:500px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> myjoin<br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">DEFAULT_DELIMITER</span>=<span style="color: #ff0000;">&quot;&quot;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #007800;">delimiter</span>=<span style="color: #800000;">${1:-$DEFAULT_DELIMITER}</span><br />
&nbsp; &nbsp; <span style="color: #007800;">inputfile</span>=$<span style="color: #000000;">2</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Avoid treating this delimiter as a regex:</span><br />
&nbsp; &nbsp; <span style="color: #007800;">delimiteresc</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$delimiter</span>&quot;</span>; <span style="color: #000000; font-weight: bold;">|</span> addslashesforsed<span style="color: #000000; font-weight: bold;">`</span><br />
<br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-v</span> <span style="color: #007800;">ORS</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$delimiter</span>&quot;</span> &nbsp;<span style="color: #ff0000;">'{print}'</span> <span style="color: #007800;">$inputfile</span> <span style="color: #000000; font-weight: bold;">|</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s/<span style="color: #007800;">$delimiteresc</span><span style="color: #000099; font-weight: bold;">\$</span>/<span style="color: #000099; font-weight: bold;">\n</span>/&quot;</span> <span style="color: #666666; font-style: italic;"># Remove the last delimiter and</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># add a new line char at the end</span><br />
<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #007800;">$?</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span></div></div>
<p>The delimiter, in this case, is a normal string but we need to prevent Sed from treating it like a <em>regex</em>, and for that I use <em>addslashesforsed</em>:</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:500px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> addslashesforsed<br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">filename</span>=$1<br />
<br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #007800;">$filename</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s#\\#\\\\#'</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s#/#\\/#'</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s#\.#\\.#'</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s#\*#\\*#'</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s#\[#\\[#'</span><br />
<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #007800;">$?</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span></div></div>
<p>By combining those two functions (<em>mysplit</em> and <em>myjoin</em>) we can obtain a lot of extra functionality. I have coded a simple function that uses both of them in order to remove a specific element from a delimited list that is stored in a string. I have called this function <em>myrmlistitems</em>, which says a lot about my (lack of) function naming skills. I wrote this one with the my previous post&#8217;s <em>addtopath</em> function in mind, so that the step where the directory to be inserted in the PATH is first removed from it could be done in a more elegant (and correct, as I have found out later) way.</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:500px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> myrmlistitems<br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">DEFAULT_DELIMITER</span>=<span style="color: #ff0000;">&quot;&quot;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #007800;">element</span>=$1<br />
&nbsp; &nbsp; <span style="color: #007800;">delimiter</span>=<span style="color: #800000;">${2:-$DEFAULT_DELIMITER}</span><br />
&nbsp; &nbsp; <span style="color: #007800;">inputfile</span>=$3<br />
<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$element</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
<br />
&nbsp; &nbsp; mysplit <span style="color: #ff0000;">&quot;<span style="color: #007800;">$delimiter</span>&quot;</span> <span style="color: #007800;">$inputfile</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;^<span style="color: #007800;">$element</span><span style="color: #000099; font-weight: bold;">\$</span>&quot;</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">|</span> myjoin <span style="color: #ff0000;">&quot;<span style="color: #007800;">$delimiter</span>&quot;</span>;<br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span></div></div>
<p>Finally, as trivial examples and just for fun, I am using <em>myjoin</em> in the process to calculate the factorial of a number, <em>myrmlistitems</em> to get rid of one of the directories in the PATH and <em>mysplit</em> to show the PATH contents in separate lines</p>
<pre>
jdevera@aurora:~$ seq 4
1
2
3
4

jdevera@aurora:~$ seq 4 | myjoin '*'
1*2*3*4

jdevera@aurora:~$ seq 4 | myjoin '*' | bc
24

jdevera@aurora:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games

jdevera@aurora:~$ echo $PATH | myrmlistitems /usr/local/bin :
/usr/bin:/bin:/usr/bin/X11:/usr/games

jdevera@aurora:~$ echo $PATH | mysplit ':'
/usr/local/bin
/usr/bin
/bin
/usr/bin/X11
/usr/games
</pre>
<img src="http://feeds.feedburner.com/~r/JacoboDeVeraWeblog/~4/Vpv6ZmvB01s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jacobodevera.com/2009/03/10/split-strings-and-join-lists-using-bash.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://blog.jacobodevera.com/2009/03/10/split-strings-and-join-lists-using-bash.html</feedburner:origLink></item>
		<item>
		<title>Adding directories to the PATH in Bash</title>
		<link>http://feedproxy.google.com/~r/JacoboDeVeraWeblog/~3/8EmBM7u3Jb0/adding-directories-to-the-path-in-bash.html</link>
		<comments>http://blog.jacobodevera.com/2009/02/21/adding-directories-to-the-path-in-bash.html#comments</comments>
		<pubDate>Sat, 21 Feb 2009 18:09:30 +0000</pubDate>
		<dc:creator>Jacobo de Vera</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://blog.jacobodevera.com/?p=36</guid>
		<description><![CDATA[When I am working on a Linux machine for which I don&#8217;t have administrator rights and want to use a program that is not available, or even a newer version of a program that&#8217;s already installed, I just install it somewhere in my home directory and add the directory where it is stored to the [...]]]></description>
			<content:encoded><![CDATA[<p>When I am working on a Linux machine for which I don&#8217;t have administrator rights and want to use a program that is not available, or even a newer version of a program that&#8217;s already installed, I just install it somewhere in my home directory and add the directory where it is stored to the PATH environment variable. If I want to override an existing version of a program that is already in the system, I will have to prefix my program&#8217;s directory to the PATH, so that it is found before its system wide counterpart. If I just want to add some functionality that was not available, I can either prefix or append the directory to the PATH. The usual way to do is is to add lines like these to the shell configuration file (<em>.bashrc</em> for my beloved Bash).</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:500px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>jdevera<span style="color: #000000; font-weight: bold;">/</span>mybinaries:<span style="color: #007800;">$PATH</span><br />
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #007800;">$PATH</span>:<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>jdevera<span style="color: #000000; font-weight: bold;">/</span>mybinaries</div></div>
<p>I find this a bit unpleasant to read, so I use these functions instead:</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:500px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> addtopath<br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">directory</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> $1 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s#/$##'</span><span style="color: #000000; font-weight: bold;">`</span> &nbsp;<span style="color: #666666; font-style: italic;"># remove trailing slash</span><br />
&nbsp; &nbsp; <span style="color: #007800;">where</span>=$<span style="color: #000000;">2</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Add only existing directories</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$directory</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> 1<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># If the directory is already in the path, remove it so that</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># it can be inserted in the desired position without </span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># poluting $PATH with duplicates</span><br />
&nbsp; &nbsp; <span style="color: #007800;">newpath</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$PATH</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">':'</span> <span style="color: #ff0000;">'\n'</span> <span style="color: #000000; font-weight: bold;">|</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;^<span style="color: #007800;">$directory</span><span style="color: #000099; font-weight: bold;">\$</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">' '</span> <span style="color: #ff0000;">':'</span><span style="color: #000000; font-weight: bold;">`</span><br />
<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$where</span> = <span style="color: #ff0000;">&quot;beg&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span> &nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Prefix to $PATH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #007800;">$directory</span>:<span style="color: #007800;">$newpath</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$where</span> = <span style="color: #ff0000;">&quot;end&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span> &nbsp;<span style="color: #666666; font-style: italic;"># Append to $PATH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #007800;">$newpath</span>:<span style="color: #007800;">$directory</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> 1<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Convenience wrappers for addtopath</span><br />
<span style="color: #666666; font-style: italic;">#</span><br />
<span style="color: #000000; font-weight: bold;">function</span> pathappend &nbsp;<span style="color: #7a0874; font-weight: bold;">&#123;</span> addtopath $1 end; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #007800;">$?</span>; <span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> pathprepend <span style="color: #7a0874; font-weight: bold;">&#123;</span> addtopath $1 beg; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #007800;">$?</span>; <span style="color: #7a0874; font-weight: bold;">&#125;</span></div></div>
<p>The main function, <em>addtopath</em>, is smarter than the previous option (exporting the new value):</p>
<ul>
<li>It checks that the directory exists before adding it to the PATH</li>
<li>It avoids duplicates in the PATH; if the directory is already in the $PATH, it is removed prior to reinsertion. This means that the directory will be moved within PATH to the desired position</li>
<li>It can prefix or append the directory to the PATH </li>
</ul>
<p>I have also written two small wrappers, <em>pathprepend</em> and <em>pathappend</em>, that prefix and append, respectively, a directory to the PATH, thus making the calls even easier and more legible.</p>
<p>I can now write something like this:</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:500px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">pathappend <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>jdevera<span style="color: #000000; font-weight: bold;">/</span>mynewbinaries<br />
pathprepend <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>jdevera<span style="color: #000000; font-weight: bold;">/</span>myoverrides</div></div>
<p>And will get them both in the PATH like this:</p>
<pre>jdevera@aurora:~$ echo $PATH
/home/jdevera/myoverrides:/usr/local/bin:/usr/bin:/bin:/usr/games:/home/jdevera/mynewbinaries</pre>
<p><strong>Edit:</strong> I added semicolons after the return statements in the wrapper functions and this now works on the Korn shell as well.</p>
<img src="http://feeds.feedburner.com/~r/JacoboDeVeraWeblog/~4/8EmBM7u3Jb0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jacobodevera.com/2009/02/21/adding-directories-to-the-path-in-bash.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blog.jacobodevera.com/2009/02/21/adding-directories-to-the-path-in-bash.html</feedburner:origLink></item>
		<item>
		<title>In The Beginning</title>
		<link>http://feedproxy.google.com/~r/JacoboDeVeraWeblog/~3/B6Q_M2D9iL0/in-the-beginning.html</link>
		<comments>http://blog.jacobodevera.com/2009/02/21/in-the-beginning.html#comments</comments>
		<pubDate>Sat, 21 Feb 2009 14:46:41 +0000</pubDate>
		<dc:creator>Jacobo de Vera</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.jacobodevera.com/?p=30</guid>
		<description><![CDATA[Finally, a brand new weblog.
I&#8217;ve written a brief introduction to myself and this blog in the About page, please have a look.
I really don&#8217;t want to write a long and convoluted first post where I would tell you what I am going to write about, I&#8217;ll write about whatever I find interesting in the fields [...]]]></description>
			<content:encoded><![CDATA[<p>Finally, a brand new weblog.</p>
<p>I&#8217;ve written a brief introduction to myself and this blog in the <a href="/about">About</a> page, please have a look.</p>
<p>I really don&#8217;t want to write a long and convoluted first post where I would tell you what I am going to write about, I&#8217;ll write about whatever I find interesting in the fields of computers, technology in general, the Internet, and all sorts of geeky stuff. I can&#8217;t promise, however, that I will always limit my articles to these topics.</p>
<p>I am using a self hosted <a href="http://wordpress.org/">WordPress</a> installation to manage this weblog and I have decided to use a theme called <a href="http://www.wpshoppe.com/themes/">simpleX</a>. This will change over time. I wanted to create my own theme from scratch and add functionality to it little by little, but I&#8217;d rather start writing now and maybe share what I learn in the process with you, my readers (if any). For the time being, Simplex is good enough: I love tags, and it supports tags!.</p>
<img src="http://feeds.feedburner.com/~r/JacoboDeVeraWeblog/~4/B6Q_M2D9iL0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jacobodevera.com/2009/02/21/in-the-beginning.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.jacobodevera.com/2009/02/21/in-the-beginning.html</feedburner:origLink></item>
	</channel>
</rss>
