<?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>the fancy part of the web &#187; bash</title>
	<atom:link href="http://blog.tolleiv.de/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tolleiv.de</link>
	<description>is elsewhere - this is just about all sorts of web related work with a small factor of fanciness</description>
	<lastBuildDate>Fri, 03 Sep 2010 15:52:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>bash: small improvement for the &#8220;cd&#8221; builtin</title>
		<link>http://blog.tolleiv.de/2009/06/improve-bash-cd-builtin/</link>
		<comments>http://blog.tolleiv.de/2009/06/improve-bash-cd-builtin/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 21:54:34 +0000</pubDate>
		<dc:creator>tolleiv</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.tolleiv.de/?p=126</guid>
		<description><![CDATA[If you use the shell and walk around in directories wou [...]]]></description>
			<content:encoded><![CDATA[<p>If you use the shell and walk around in directories wouldn&#8217;t it be cool to have &#8220;cd &#8230;&#8221; to move 2 levels up, &#8220;cd &#8230;.&#8221; to move 3 levels up &#8230;? I&#8217;m not sure if there&#8217;s an easier way to resolve it but the following lines work pretty nice so far and they just made it into my default .bashrc <img src='http://blog.tolleiv.de/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<pre name="code" class="php">cd() {
	if [[ "$1" =~ ^\.\.\.+$  ]]; then
		cd `echo "$1" | sed 's/\./..\//g' | sed 's/^\.\.\///g'`
	else
		builtin cd "$1"
	fi
}</pre>
<p>For different older shell/bash versions you might need quotes around the regex.</p>
<p>Btw <a href="http://books.google.de/books?id=WQCSxv9vfPkC&amp;lpg=PA84&amp;ots=OiT8hUe10J&amp;dq=bash%20function%20with%20the%20same%20name%20as%20command&amp;pg=PP1" target="_blank">O&#8217;Reilly&#8217;s &#8220;Learning the Bash&#8221;</a> is available within Google Books</p>
<p><em>Edit: another very important bookmark for bashscripting is the <a href="http://tldp.org/LDP/abs/html/">Advanced Bash-Scripting Guide</a></em></p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://blog.tolleiv.de/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.tolleiv.de/2009/06/improve-bash-cd-builtin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>shell command: translate</title>
		<link>http://blog.tolleiv.de/2009/04/shell-command-translare/</link>
		<comments>http://blog.tolleiv.de/2009/04/shell-command-translare/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 16:22:55 +0000</pubDate>
		<dc:creator>tolleiv</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.tolleiv.de/?p=33</guid>
		<description><![CDATA["Translate, squeeze, and/or delete characters from stan [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>&#8220;Translate, squeeze, and/or delete characters from standard input,<br />
writing to standard output.&#8221;</p></blockquote>
<p>&#8230; that&#8217;s the manpage description of the shell-command I just found (with the help of a good friend) &#8230; and besides sed this is a very handy way to do simple string-operations on stdin.</p>
<p>He used it to replace (old) Mac newline characters with Unix newline charaters within files (as seen on <a href="http://en.wikipedia.org/wiki/Newline">wikipedia</a>):<br />
<code>tr '\r' '\n' &lt; old.file &gt; new.file</code></p>
<p>Btw I still think that it&#8217;s stupid that users still have all the hazzle with <a href="http://en.wikipedia.org/wiki/Newline">newline charaters</a> &#8211; why can&#8217;t the OS-developers just recognize all types of newlines? <img src='http://blog.tolleiv.de/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.14';
var flattr_uid = '23199';
var flattr_url = 'http://blog.tolleiv.de';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'the fancy part of the web';
var flattr_dsc = 'is elsewhere - this is just about all sorts of web related work with a small factor of fanciness';
</script>
<script src="https://api.flattr.com/js/0.5.0/load.js?mode=auto" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://blog.tolleiv.de/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.tolleiv.de/2009/04/shell-command-translare/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>find the newest file within a folder&#8230;.</title>
		<link>http://blog.tolleiv.de/2009/04/find-the-newest-file-within-a-folder/</link>
		<comments>http://blog.tolleiv.de/2009/04/find-the-newest-file-within-a-folder/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 20:14:42 +0000</pubDate>
		<dc:creator>tolleiv</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.tolleiv.de/?p=3</guid>
		<description><![CDATA[These are two neat little commands to find the newest a [...]]]></description>
			<content:encoded><![CDATA[<p>These are two neat little commands to find the newest and oldest file within a folder and it&#8217;s subfolder:<br />
<code> find . -type f -printf "%T@ %p \n" | sort -n -k 1,1 | awk '{print $2}' | tail -n 1<br />
find . -type f -printf "%T@ %p \n" | sort -n -k 1,1 | awk '{print $2}' | head -n 1</code><br />
If you&#8217;d like to know how old/young these files are try these two:<br />
<code>find . -type f -printf "%T@ %C+ %p \n" | sort -n -k 1,1 | tail -n 1<br />
find . -type f -printf "%T@ %C+ %p \n" | sort -n -k 1,1 | head -n 1</code></p>
<p>I hope that&#8217;s a good starter for the &#8220;blog&#8221; <img src='http://blog.tolleiv.de/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://blog.tolleiv.de/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.tolleiv.de/2009/04/find-the-newest-file-within-a-folder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>track time for a subroutine within a shell-script</title>
		<link>http://blog.tolleiv.de/2008/07/track-time-for-a-subroutine-within-a-shell-script/</link>
		<comments>http://blog.tolleiv.de/2008/07/track-time-for-a-subroutine-within-a-shell-script/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 21:55:00 +0000</pubDate>
		<dc:creator>tolleiv</dc:creator>
				<category><![CDATA[offtopic]]></category>
		<category><![CDATA[shellscript]]></category>
		<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://blog.tolleiv.de/2008/07/track-time-for-a-subroutine-within-a-shell-script/</guid>
		<description><![CDATA[The following code-snippet is a shell-script which does [...]]]></description>
			<content:encoded><![CDATA[<p>The following code-snippet is a shell-script which does the following:</p>
<ol>
<li>Track the time for a block of shell commands</li>
<li>Check if the time was less than x seconds (the example uses 10 seconds)
</li>
<li>If the block run through too fast the script waits/sleeps a few seconds</li>
<li>Run all this within a loop so that the block of shell-commands is executed periodically</li>
</ol>
<p>I used the script combined with a PHP script which processes a queue. The PHP script processes 1000 elements from the queue and takes about 30 seconds for that. Since just having a cronjob per minute would be not efficient enought I used this script.<br />
The waiting-block is necessary because now and then the queue is empty &#8230; but I think there are lot&#8217;s of situations where a script like this can be usefull:</p>
<pre name="code" class="php">
#!/bin/bash
while [ 1 -ge 0 ]; do
time_begin=`date +%s`

###BLOCK 2 TRACK - BEGIN
number=$RANDOM
let "number %= 20"
sleep $number
###BLOCK 2 TRACK - END

time_end=`date +%s`
total=$((time_end-time_begin))

if [[ $total -ge 10 ]]; then
echo "time taken was: $number : $total"
else
echo "time take was too less  $number : $total"
sleep 10
fi
done
</pre>
<script type="text/javascript">
var flattr_wp_ver = '0.9.14';
var flattr_uid = '23199';
var flattr_url = 'http://blog.tolleiv.de';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'the fancy part of the web';
var flattr_dsc = 'is elsewhere - this is just about all sorts of web related work with a small factor of fanciness';
</script>
<script src="https://api.flattr.com/js/0.5.0/load.js?mode=auto" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://blog.tolleiv.de/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.tolleiv.de/2008/07/track-time-for-a-subroutine-within-a-shell-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
