<?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>Silas Sewell - Bash</title>
        <atom:link href="http://www.silassewell.com/blog/tag/bash/rss2.xml" rel="self" type="application/rss+xml" />
        <link>http://www.silassewell.com/blog/tag/bash</link>
        <description>Infrastructure Development</description>
        <lastBuildDate>Sat, 21 Aug 2010 00:00:00 GMT</lastBuildDate>
        <generator>http://www.silassewell.com/</generator>
        <language>en</language>
        <sy:updatePeriod>hourly</sy:updatePeriod>
        <sy:updateFrequency>1</sy:updateFrequency>

        <item>
            <title>String Slicing in Bash (like Python)</title>
            <link>http://www.silassewell.com/blog/2009/03/12/string-slicing-in-bash-like-python/</link>
            <pubDate>Thu, 12 Mar 2009 00:00:00 GMT</pubDate>
            <dc:creator>silas</dc:creator>
            <category><![CDATA[Bash]]></category><category><![CDATA[Programming]]></category><category><![CDATA[Python]]></category><category><![CDATA[String]]></category><category><![CDATA[Systems Administration]]></category>
            <guid isPermaLink="true">http://www.silassewell.com/blog/2009/03/12/string-slicing-in-bash-like-python/</guid>
            <description><![CDATA[<p>A simple function to slice strings in Bash similar to Python's string slicing functionality.</p>

<h3>Examples</h3>

<pre><code class="prettyprint">[silas@pluto ~]$ string_slice "12345" 0 1
1
[silas@pluto ~]$ string_slice "12345" 0 3
123
[silas@pluto ~]$ string_slice "12345" 2 3
3
[silas@pluto ~]$ string_slice "12345" 2 -2
3
[silas@pluto ~]$ string_slice "12345" -3
345
</code></pre>

<h3>Implementation</h3>

<pre><code class="prettyprint">function string_slice {
    STRING="$1"
    declare -i LENGTH="${#STRING}"
    declare -i START="$2"
    declare -i END="$3"
    if [ $START -lt 0 ]; then
        START=$[ $LENGTH + $START ]
    fi
    if [ $END -le 0 ]; then
        END=$[ $LENGTH + $END ]
    fi
    START=$[ $START + 1 ]
    (echo "$STRING" | cut -c $START-$END) 2&gt; /dev/null
}
</code></pre>]]></description>
        </item>

        <item>
            <title>Profile Management with Git and GitHub</title>
            <link>http://www.silassewell.com/blog/2009/03/08/profile-management-with-git-and-github/</link>
            <pubDate>Sun, 08 Mar 2009 00:00:00 GMT</pubDate>
            <dc:creator>silas</dc:creator>
            <category><![CDATA[Bash]]></category><category><![CDATA[Configuration Management]]></category><category><![CDATA[Git]]></category><category><![CDATA[Projects]]></category><category><![CDATA[Systems Administration]]></category>
            <guid isPermaLink="true">http://www.silassewell.com/blog/2009/03/08/profile-management-with-git-and-github/</guid>
            <description><![CDATA[<p>The following describes a simple way to manage you profile configuration files using GitHub.</p>

<h3>Features</h3>

<ul>
<li>Centralized configuration management</li>
<li>Files live in their native locations (no symbolic linking)</li>
<li>Home directory is not a Git repository</li>
<li>All the power of git with a simple alias</li>
</ul>

<h3>Setup Repository</h3>

<ul>
<li>Log into <a href="http://github.com/" title="GitHub">GitHub</a> and create a repository named config</li>
<li>Add your <a href="http://github.com/guides/providing-your-ssh-key" title="Public Keys to GithHub">public keys to GitHub</a> (if you haven't done so already)</li>
<li><p>Open a terminal and switch to your home directory</p>

<pre><code class="prettyprint">cd ~
</code></pre></li>
<li><p>Create a configuration directory</p>

<pre><code class="prettyprint">mkdir .config.git
</code></pre></li>
<li><p>Add the following alias to your current session and your <code class="prettyprint">.bash_profile</code></p>

<pre><code class="prettyprint">alias config='git --git-dir=$HOME/.config.git/ --work-tree=$HOME'
echo "alias config='git --git-dir=$HOME/.config.git/ --work-tree=$HOME'" &gt;&gt; .bash_profile
</code></pre></li>
<li><p>Add your <code class="prettyprint">.bash_profile</code> to the configuration repository</p>

<pre><code class="prettyprint">config add .bash_profile
</code></pre></li>
<li><p>Commit the changes</p>

<pre><code class="prettyprint">config commit -m 'Initial commit'
</code></pre></li>
<li><p>Change the origin to GitHub</p>

<pre><code class="prettyprint">config remote add origin git@github.com:GITHUB_USERNAME/config.git
</code></pre></li>
<li><p>Push the changes</p>

<pre><code class="prettyprint">config push origin master
</code></pre></li>
</ul>

<p>If you get an error when running <code class="prettyprint">config pull</code> to the effect of <code class="prettyprint">You asked me to pull without...</code> run the follow:</p>

<pre><code class="prettyprint">    echo -e '[branch "master"]\n  remote = origin\n  merge = refs/heads/master' &gt;&gt; ~/.config.git/config
</code></pre>

<h3>Setup Configuration Management on a Different System</h3>

<ol>
<li>Add your <a href="http://github.com/guides/providing-your-ssh-key" title="Public Keys to GithHub">public keys to GitHub</a> (if you haven't done so already)</li>
<li><p>Switch to your home directory</p>

<pre><code class="prettyprint">cd ~
</code></pre></li>
<li><p>Backup your local configuration files, example:</p>

<pre><code class="prettyprint">mv .bash_profile .bash_profile.bk
</code></pre></li>
<li><p>Clone your configuration repository</p>

<pre><code class="prettyprint">git clone git@github.com:GITHUB_USERNAME/config.git config.git
</code></pre></li>
<li><p>Move the git metadata to <code class="prettyprint">~/.config.git</code></p>

<pre><code class="prettyprint">mv config.git/.git .config.git
</code></pre></li>
<li><p>Enable dotglob</p>

<pre><code class="prettyprint">shopt -s dotglob
</code></pre></li>
<li><p>Move your configuration files to your home directory</p>

<pre><code class="prettyprint">mv -i config.git/* .
</code></pre></li>
<li><p>Delete the <code class="prettyprint">config.git</code> directory</p>

<pre><code class="prettyprint">rmdir config.git
</code></pre></li>
<li><p>Logout and log back in</p></li>
</ol>

<h3>Basic Usage</h3>

<ul>
<li><code class="prettyprint">config pull</code> - get latest configuration changes</li>
<li><code class="prettyprint">config add FILENAME</code> - add a configuration file</li>
<li><code class="prettyprint">config commit -a</code> - save all configuration changes</li>
<li><code class="prettyprint">config push</code> - push configuration changes to GitHub</li>
<li>and any other <code class="prettyprint">config GIT_OPTION</code></li>
</ul>

<p>You can see my configuration repository at <a href="http://github.com/silas/config" title="config">http://github.com/silas/config</a>.</p>

<p>Source: <a href="http://robescriva.com/2009/01/manage-your-home-with-git/" title="source">Manage your $HOME with git</a> by Robert Escriva</p>]]></description>
        </item>

        <item>
            <title>IPython + Python: Single Bash Command</title>
            <link>http://www.silassewell.com/blog/2008/12/01/ipython-python-single-bash-command/</link>
            <pubDate>Mon, 01 Dec 2008 00:00:00 GMT</pubDate>
            <dc:creator>silas</dc:creator>
            <category><![CDATA[Bash]]></category><category><![CDATA[IPython]]></category><category><![CDATA[Python]]></category><category><![CDATA[Systems Administration]]></category>
            <guid isPermaLink="true">http://www.silassewell.com/blog/2008/12/01/ipython-python-single-bash-command/</guid>
            <description><![CDATA[<p>The following is a simple Bash function you can paste into your bashrc file to
start Python/IPython depending on the context.</p>

<h3>~/.bashrc</h3>

<pre><code class="prettyprint">function python {
    IPYTHON="/usr/bin/ipython"
    PYTHON="/usr/bin/python"

    if [[ -n $1 ]]; then
        $PYTHON $@
    elif [[ -e $IPYTHON ]]; then
        $IPYTHON
    else
        $PYTHON
    fi
}
</code></pre>]]></description>
        </item>

        <item>
            <title>Simple Shell Script to Manage SSH Tunnels</title>
            <link>http://www.silassewell.com/blog/2007/12/15/simple-shell-script-manage-ssh-tunnels/</link>
            <pubDate>Sat, 15 Dec 2007 00:00:00 GMT</pubDate>
            <dc:creator>silas</dc:creator>
            <category><![CDATA[Bash]]></category><category><![CDATA[CLI]]></category><category><![CDATA[Operating Systems]]></category><category><![CDATA[SSH]]></category>
            <guid isPermaLink="true">http://www.silassewell.com/blog/2007/12/15/simple-shell-script-manage-ssh-tunnels/</guid>
            <description><![CDATA[<p>Manage SSH Tunnel is a simple shell script to start and stop ssh tunnels from the terminal.</p>

<h3>Setup</h3>

<p>Note: the setup assumes bash as the default shell</p>

<ol>
<li>Download <a href="http://www.silassewell.com/blog/2007/12/15/simple-shell-script-manage-ssh-tunnels/tunnel.sh">tunnel.sh</a> and save it to ~/bin/</li>
<li><p>Add to <code class="prettyprint">~/.bash_profile</code> or <code class="prettyprint">~/.bashrc</code></p>

<pre><code class="prettyprint">alias tunnel_home='/bin/sh ~/bin/tunnel.sh example.net sam 22 8888'
</code></pre></li>
<li><p>Replace example.net with the hostname of the server, sam with the username
on the server, and 8888 with the local tunnel port</p></li>
<li>Type <code class="prettyprint">source ~/.bash_profile</code> or <code class="prettyprint">source ~/.bashrc</code></li>
</ol>

<h3>Usage</h3>

<ol>
<li><p>To open the tunnel</p>

<pre><code class="prettyprint">tunnel_home start
</code></pre></li>
<li><p>To close the tunnel</p>

<pre><code class="prettyprint">tunnel_home close
</code></pre></li>
</ol>]]></description>
        </item>

    </channel>
</rss>