<?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>Raim &#187; shell</title>
	<atom:link href="http://raim.codingfarm.de/blog/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://raim.codingfarm.de/blog</link>
	<description>My personal front yard on the web</description>
	<lastBuildDate>Sat, 03 Jul 2010 20:31:31 +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>pastie.org shell script</title>
		<link>http://raim.codingfarm.de/blog/2010/04/06/pastie-org-shell-script/</link>
		<comments>http://raim.codingfarm.de/blog/2010/04/06/pastie-org-shell-script/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 00:53:15 +0000</pubDate>
		<dc:creator>Rainer Müller</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[pastie]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://raim.codingfarm.de/blog/?p=148</guid>
		<description><![CDATA[I wrote a bash script to create new pastes on pastie.org. It features automatic source language selection based on the file extension and has a switch to make a private paste. $ pastie --help Usage: pastie [options] [files...] Options: -h, --help display this help -l, --lang set language of the paste -p, --private make paste [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a bash script to create new pastes on <a href="http://pastie.org">pastie.org</a>. It features automatic source language selection based on the file extension and has a switch to make a private paste.</p>
<pre>
$ pastie --help
Usage: pastie [options] [files...]

Options:
    -h, --help          display this help
    -l, --lang <lang>   set language of the paste
    -p, --private       make paste private

If --lang is not specified, this script will try to determine the type of each
file automatically based on the extension. If no files are given on the
command line it reads from standard input.
</pre>
<p>You can download it here:<br />
<a href="http://pastie.org/904797">http://pastie.org/904797</a></p>
<p>The script is public domain, so do whatever you want with it.</p>
<p>Although this is the initial release, I bumped the version number to 1.6 already. During testing the script I pasted itself several times to <a href="http://pastie.org">pastie.org</a>. I set a arbitrary higher version number to avoid confusion in case the previous pastes ever turn up in Google or wherever.</p>
<p><strong>Update:</strong><br />
Seems like their parser for shell is a bit broken and doubles the heredoc starting and ending sequences in the output. For whatever reason it appears as &#8220;&lt;&lt;END&lt;&lt;END&#8221;. Please use the <a href="http://pastie.org/904797.txt">raw version</a> for download instead of copy &#038; paste.</p>
]]></content:encoded>
			<wfw:commentRss>http://raim.codingfarm.de/blog/2010/04/06/pastie-org-shell-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculating sum of numbers in the shell</title>
		<link>http://raim.codingfarm.de/blog/2010/03/12/calculating-sum-of-numbers-in-the-shell/</link>
		<comments>http://raim.codingfarm.de/blog/2010/03/12/calculating-sum-of-numbers-in-the-shell/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 23:13:28 +0000</pubDate>
		<dc:creator>Rainer Müller</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[numbers]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[sum]]></category>

		<guid isPermaLink="false">http://raim.codingfarm.de/blog/?p=131</guid>
		<description><![CDATA[More than one time I wanted to sum up numbers in the shell. Imagine a command producing a list of numbers like this: $ ... 42 23 966 1764 529 4711 Now calculating the sum of these numbers is not trivial. Using tools like bc or calc directly is not possible because you would need [...]]]></description>
			<content:encoded><![CDATA[<p>More than one time I wanted to sum up numbers in the shell. </p>
<p>Imagine a command producing a list of numbers like this:</p>
<blockquote><p>
<code><br />
$ ...<br />
42<br />
23<br />
966<br />
1764<br />
529<br />
4711<br />
</code>
</p></blockquote>
<p>Now calculating the sum of these numbers is not trivial. Using tools like <code>bc</code> or <code>calc</code> directly is not possible because you would need to put plus signs between the numbers first. So you could probably replace all &#8216;\n&#8217; with &#8216;+&#8217; with <code>tr</code> &mdash; but not the last one as that would lead to a syntax error later. Or as an alternative you could write a long shell construct with <code>while read ...</code> etc. In short this is just getting way too complicated for such a simple task.</p>
<p>Here is the simple solution in <code>awk</code>:</p>
<blockquote><p>
<code><br />
$ ... | awk 'BEGIN {total = 0} {total += $1} END {print total}'<br />
8035<br />
</code>
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://raim.codingfarm.de/blog/2010/03/12/calculating-sum-of-numbers-in-the-shell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hiding MOTD on bash startup</title>
		<link>http://raim.codingfarm.de/blog/2009/05/03/hiding-motd-on-bash-startup/</link>
		<comments>http://raim.codingfarm.de/blog/2009/05/03/hiding-motd-on-bash-startup/#comments</comments>
		<pubDate>Sun, 03 May 2009 16:08:33 +0000</pubDate>
		<dc:creator>Rainer Müller</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[motd]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://raim.codingfarm.de/blog/?p=49</guid>
		<description><![CDATA[Usually bash displays /etc/motd at the time of last login on opening a new shell. I do not find that information very useful, as I am opening new shells a lot, so the time does not really mean anything for me. Also, the MOTD rarely changes. There is a feature in bash to hide these [...]]]></description>
			<content:encoded><![CDATA[<p>Usually bash displays <code>/etc/motd</code> at the time of last login on opening a new shell. I do not find that information very useful, as I am opening new shells a lot, so the time does not really mean anything for me. Also, the MOTD rarely changes.</p>
<p>There is a feature in bash to hide these messages by creating a file <code>~/.hushlogin</code>. This will make bash jump right to the first prompt without any output before.</p>
<p>But just in case the MOTD changes and includes important messages, I enhanced this setup a little bit. Instead of just touching the <code>.hushlogin</code> file, I am storing the old MOTD in it. At startup the old and current MOTD is compared against each other and will be displayed only if it differs. To avoid accidentally missing the MOTD, bash will also ask for my confirmation that I have read it.</p>
<p>Here is the snippet from my <code>~/.bashrc</code>:</p>
<pre>
# Show motd only if necessary
cmp -s $HOME/.hushlogin /etc/motd
if [ $? != 0 ]; then
    echo -e "\n==> !!! IMPORTANT: /etc/motd changed !!! <==\n"
    cat /etc/motd
    echo -e "\n==> !!! IMPORTANT: /etc/motd changed !!! <==\n"
    read -e -n 1 -p "Show again? (Y/n) " ans
    if [ "$ans" == "n" ]; then
        cat /etc/motd > $HOME/.hushlogin
    fi
fi
</pre>
<p><strong>Please note:</strong> If you are going to use this, make sure it will not get executed on non-interactive shells. Otherwise it can break tools like scp, sftp or rsync. To ensure this will not be used on non-interactive shells, I am using this conditional at the top of my <code>~/.bashrc</code>:</p>
<pre>
if [[ $- != *i* ]] ; then
    # Shell is non-interactive.  Be done now!
    return
fi
</pre>
]]></content:encoded>
			<wfw:commentRss>http://raim.codingfarm.de/blog/2009/05/03/hiding-motd-on-bash-startup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subversion diff commands</title>
		<link>http://raim.codingfarm.de/blog/2009/03/17/subversion-diff-commands/</link>
		<comments>http://raim.codingfarm.de/blog/2009/03/17/subversion-diff-commands/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 10:58:36 +0000</pubDate>
		<dc:creator>Rainer Müller</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[diff]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://raim.codingfarm.de/blog/?p=28</guid>
		<description><![CDATA[Subversion allows to use a custom command for displaying diffs using svn diff --diff-cmd &#60;cmd&#62;. I have been using diff-cmd=colordiff in my ~/.subversion/config for quite some time now. This is really useful, but occasionally I would also like to use vimdiff to get a nice side-by-side diff. Although this sounds quite easy at first, there [...]]]></description>
			<content:encoded><![CDATA[<p>Subversion allows to use a custom command for displaying diffs using <code>svn diff --diff-cmd &lt;cmd&gt;</code>. I have been using <code>diff-cmd=colordiff</code> in my <i>~/.subversion/config</i> for quite some time now. This is really useful, but occasionally I would also like to use vimdiff to get a nice side-by-side diff.</p>
<p>Although this sounds quite easy at first, there are some hurdles. Subversion expects the given command to adhere to the GNU diff parameters, that means it expects it to understand and parse the labels it passes before the actual filenames. This works fine for colordiff, but not vimdiff which only wants the old and new filenames.</p>
<p>For a better diff experience with svn, I set up the following shell function which let&#8217;s me choose the program I want to use for diffing.</p>
<p>First, I need a new wrapper script at <i>~/libexec/svndiff</i> which takes the actual diff program as first option, ignores the GNU diff labels and calls that program passing old and new filename.</p>
<pre>
#!/bin/bash
BIN=$1
shift 5
$BIN "$@"
</pre>
<p>Then I define this shell alias in my <i>~/.bashrc</i> to extend the functionality of the svn command:</p>
<pre>
function svn() {
    case "$1" in
        diff-plain)
            shift;
            `which svn` diff --diff-cmd diff $@
            ;;
        diff-color)
            shift;
            `which svn` diff --diff-cmd colordiff $@
            ;;
        diff-vim)
            shift;
            `which svn` diff --diff-cmd $HOME/libexec/svndiff -x vimdiff $@
            ;;
        diff-filemerge)
            shift;
            `which svn` diff --diff-cmd $HOME/libexec/svndiff -x opendiff $@
            ;;
        *)
            `which svn` $@
            ;;
    esac
}
</pre>
<p>Now I can choose the program I find best suited for the current task in a very simplified manner, for example <code>svn diff-vim -c1337</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://raim.codingfarm.de/blog/2009/03/17/subversion-diff-commands/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
