<?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>Kyle Brandt &#187; Bash</title>
	<atom:link href="http://www.kbrandt.com/category/bash/feed" rel="self" type="application/rss+xml" />
	<link>http://www.kbrandt.com</link>
	<description>Original computing and productivity articles by a Linux administrator</description>
	<lastBuildDate>Tue, 06 Jul 2010 01:04:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Cross Compile the Bash shell for Android 1.5</title>
		<link>http://www.kbrandt.com/2009/06/how-to-cross-compile-the-bash-shell-for-android-15.html</link>
		<comments>http://www.kbrandt.com/2009/06/how-to-cross-compile-the-bash-shell-for-android-15.html#comments</comments>
		<pubDate>Sun, 28 Jun 2009 18:28:53 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.kbrandt.com/?p=334</guid>
		<description><![CDATA[Introduction:
I just got a new G1 Android phone, and since it runs Linux I just had to get the Bash shell running on it, the built in shell would just not do.  I do need my tab completion after all. Cross compilation is the process of compiling software on one platform that is meant to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction:</strong><br />
I just got a new G1 Android phone, and since it runs Linux I just had to get the Bash shell running on it, the built in shell would just not do.  I do need my tab completion after all. Cross compilation is the process of compiling software on one platform that is meant to run on another.  With the following an ARM executable is compiled on a x86 Linux machine.</p>
<p>Requirements (Not sure if all this is needed, but it is what I used):</p>
<ul>
<li> Cupcake 1.5 JS Build with root access: <a href="http://androidandme.com/2009/05/guides/beginners-guide-for-rooting-your-android-g1-to-install-cupcake/" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://androidandme.com/2009/05/guides/beginners-guide-for-rooting-your-android-g1-to-install-cupcake/');">http://androidandme.com/2009/05/guides/beginners-guide-for-rooting-your-android-g1-to-install-cupcake/</a></li>
<li>ARM Toolkit (The Cross Compiler):  <a href="http://www.codesourcery.com/gnu_toolchains/arm/download.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.codesourcery.com/gnu_toolchains/arm/download.html');">http://www.codesourcery.com/gnu_toolchains/arm/download.html</a></li>
<li>Android SDK installed on Linux: <a href="http://developer.android.com/sdk/1.5_r2/index.htm" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://developer.android.com/sdk/1.5_r2/index.htm');">http://developer.android.com/sdk/1.5_r2/index.htm</a></li>
<li>A G1</li>
<li>The source code for Bash 4.0: <a href="ftp://ftp.cwru.edu/pub/bash/bash-4.0.tar.gz" onclick="javascript:pageTracker._trackPageview('/outbound/article/ftp://ftp.cwru.edu/pub/bash/bash-4.0.tar.gz');">ftp://ftp.cwru.edu/pub/bash/bash-4.0.tar.gz</a></li>
</ul>
<p><strong>Step 1: Connect your pc to your phone with the SDK</strong><br />
You first have to be able to connect to your computer with adp which is included with the sdk.  To do this with Ubuntu Januty Jackalope you first need to create a /etc/udev/rules.d/51-android.rules file with the following contents:</p>
<pre class="brush: php">SUBSYSTEM==&quot;usb&quot;, SYSFS{idVendor}==&quot;0bb4&quot;, MODE=&quot;0666&quot;</pre>
<p>After this run the following to restart udev: &#8217;sudo /etc/init.d/udev reload&#8217;.  Lastly, on your phone make sure Settings :: Applications :: Development :: USB Debugging is enabled and the plug in your phone.  When you run &#8216;./adp devices&#8217; you should see a device listed.</p>
<p><strong>Step 2: Build the Bash Shell</strong><br />
After installing ARM toolkit in /home/kbrandt/bin/arm-toolkit (used for this example) set the following environment variables in your shell.</p>
<pre class="brush: php">CC=&#039;/home/kbrandt/bin/arm-toolkit/bin/arm-none-linux-gnueabi-gcc&#039;
PATH=&quot;$PATH:$HOME/bin/&quot;
</pre>
<p>Then cd to the directory where you extracted the Bash source and run the following:</p>
<pre class="brush: php">./configure --prefix=/opt/arm_bash/ -host=arm-linux --enable-static-link --without-bash-malloc
</pre>
<p>Assuming that worked, edit the &#8216;Makefile&#8217; file and change &#8216;CFLAGS = -g -O2&#8242; to &#8216;CFLAGS = -g -O2 -static&#8217; and then run &#8216;make&#8217;.  If this works, it should create a bash executable in the current directory.  You can verify that this has been compiled for the ARM architecture with &#8216;file bash&#8217;.  This should return:</p>
<p>bash: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped</p>
<p><strong>Step 3: Copy the File to your android.</strong><br />
From the host computer in the tools directory of the SDK run &#8216;./adb push ~/src/bash-4.0/bash /data/&#8217; to copy the executable to the phone.  If you try to copy it to your sdcard, make sure the sdcard is not mounted with the noexec mount option as this disables the executable permission bit.</p>
<p><strong>Step 4: Run, Enjoy, and Find Bugs.</strong><br />
You can now connect to your phone with &#8216;./adp shell&#8217; and cd to the data directory and run &#8216;./bash&#8217; and you should get a bash prompt.  You might need to &#8216;chmod 555 bash&#8217; if you get permission denied.</p>
<p>References:<br />
<a href="http://jiggawatt.org/badc0de/android/index.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://jiggawatt.org/badc0de/android/index.html');">http://jiggawatt.org/badc0de/android/index.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kbrandt.com/2009/06/how-to-cross-compile-the-bash-shell-for-android-15.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Bash Snippet: Sort Files by Part of the Filename</title>
		<link>http://www.kbrandt.com/2008/07/bash-snippet-sort-files-by-part-of.html</link>
		<comments>http://www.kbrandt.com/2008/07/bash-snippet-sort-files-by-part-of.html#comments</comments>
		<pubDate>Sat, 19 Jul 2008 15:32:00 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.kbrandt.com/?p=30</guid>
		<description><![CDATA[The Situation:
I have several directories with various GUN/Linux e-books in them.  The names of the e-books have the publication date in them, but not in the same place. What I wanted to do was get a list of the books sorted by the publication date.
My Solution:
The solution I used was to create a column [...]]]></description>
			<content:encoded><![CDATA[<p>The Situation:<br />
I have several directories with various GUN/Linux e-books in them.  The names of the e-books have the publication date in them, but not in the same place. What I wanted to do was get a list of the books sorted by the publication date.</p>
<p>My Solution:<br />
The solution I used was to create a column of the years and then a second column that listed all the file names. Then all that needed to be done was to sort based on the year column, which was even simpler because it was the first column.  However, this seems quite slow, anyone have a better solution?</p>
<p>for book in Linux\ */*; do echo &#8220;$(echo ${book##*/} | egrep -o &#8216;[0-9]{4}&#8217;) : ${book##*/}&#8221;; done | sort</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kbrandt.com/2008/07/bash-snippet-sort-files-by-part-of.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Thinking about Bash Redirection and File Descriptors</title>
		<link>http://www.kbrandt.com/2008/06/quick-tip-thinking-about-bash.html</link>
		<comments>http://www.kbrandt.com/2008/06/quick-tip-thinking-about-bash.html#comments</comments>
		<pubDate>Mon, 16 Jun 2008 15:57:00 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.kbrandt.com/?p=27</guid>
		<description><![CDATA[A common question that comes up from people new to bash scripting is: &#8220;How do I redirect standard error to standard out?&#8221; There are a few ways to write this but the clearest way in my opinion is &#8220;command 2&#62;&#38;1&#8243;.  File descriptor 2 is standard error, and 1 is standard out.  So &#8220;2&#62;&#38;1&#8243; [...]]]></description>
			<content:encoded><![CDATA[<p>A common question that comes up from people new to bash scripting is: &#8220;How do I redirect standard error to standard out?&#8221; There are a few ways to write this but the clearest way in my opinion is &#8220;command 2&gt;&amp;1&#8243;.  File descriptor 2 is standard error, and 1 is standard out.  So &#8220;2&gt;&amp;1&#8243; reads in the form of the question: &#8220;File descriptor 2  is being redirected to file descriptor 1.&#8221;</p>
<p>However, I think that question itself causes confusion.  I don&#8217;t think the phrase should be &#8220;redirecting standard error to standard out.&#8221;  Rather, you are redirecting standard error to <span style="font-style: italic;">where</span> standard out <span style="font-style: italic;">points to</span>. You can also think &#8220;the file descriptors describe the files they point too.&#8221;  To see this behavior, you can run &#8216;xclock 1&gt; ~/scrap/foo 2&gt;&amp;1 &#8216;.  What this does is redirect standard error to where standard out points to, and then redirects standard output to &#8216;~/scrap/foo&#8217;.  If you run the following: &#8216;ls -l /proc/<span style="font-style: italic;">pid_of_xclock/</span>fd&#8217;, you will see the above described behavior in action.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kbrandt.com/2008/06/quick-tip-thinking-about-bash.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash: Getting Command Line Columns to Line up</title>
		<link>http://www.kbrandt.com/2008/06/bash-getting-command-line-columns-to.html</link>
		<comments>http://www.kbrandt.com/2008/06/bash-getting-command-line-columns-to.html#comments</comments>
		<pubDate>Fri, 06 Jun 2008 15:52:00 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.kbrandt.com/?p=25</guid>
		<description><![CDATA[Update: David Harding pointed out in his comment to this post that the column utility does exactly this. Therefore, the following is really just an academic exercise.
In my last post I showed how to get columns outputted in the command line to line up using python.  In this post I am going to show [...]]]></description>
			<content:encoded><![CDATA[<p>Update: David Harding pointed out in his comment to this post that the column utility does exactly this. Therefore, the following is really just an academic exercise.</p>
<p>In my last post I showed how to get columns outputted in the command line to line up using python.  In this post I am going to show you how to do it with Bash scripts (I think you could also use this same method with python using calls to the shell).  Instead of padding the columns with spaces as I did in my previous post, this time we use a tab character for the delimiter and manually set the tab stops in the terminal itself.  Since this is the terminal, not the shell, this will work with other shells as well (such as my favorite interactive shell, Zsh).</p>
<p>There is example code at the bottom.  Instead of creating functions as I did with my previous post I have kept this example pretty tedious (repetitive code etc) to lessen the levels of abstraction and make the example a little clearer.</p>
<p>The first part finds the max width of each column of a text file.  This example has 4 columns and a while loop that splits them on the tab character by setting the IFS ( Input Field Separator ) variable to tab for the loop only.  Each iteration of the while loop remembers the value of each column; it saves the value in the $max# variable if the length was larger then the previous iteration ( the variable substitution ${#variable} returns the length of the variable ).</p>
<p>The second part, after the while loop, finds where the tab stops should be placed.  The setterm command with the -tabs switch sets tab stops at absolute positions up to 160 ( each argument specifies where the tab stop is relative to the start of the line, not relative to the previous tab stop ) .  So for this example, the second tab stop position is found by adding the width of the first column to the width of second column &#8212; this gives us the position relative to the start of line.  Lastly, after setting the tab stops the file is displayed on the terminal with cat.</p>
<p>A caveat is that it is hard to find out what to set $TERM to.  On my machine, when I am in screen session $TERM is equal to &#8217;screen&#8217;, but this doesn&#8217;t work with setterm, I have to set TERM to &#8216;linux&#8217;.</p>
<p>I hope this helps someone when creating their next command line utility that uses columns.</p>
<p><a href="http://kmbrandt.googlepages.com/bash_col.jpg" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://kmbrandt.googlepages.com/bash_col.jpg');" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="cursor: pointer;" src="http://kmbrandt.googlepages.com/bash_col.jpg" border="0" alt="" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kbrandt.com/2008/06/bash-getting-command-line-columns-to.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Thunderbird Email from the Command Line</title>
		<link>http://www.kbrandt.com/2008/05/quick-tip-tunderbird-email-from-command.html</link>
		<comments>http://www.kbrandt.com/2008/05/quick-tip-tunderbird-email-from-command.html#comments</comments>
		<pubDate>Sat, 10 May 2008 15:31:00 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Thunderbird]]></category>

		<guid isPermaLink="false">http://www.kbrandt.com/?p=22</guid>
		<description><![CDATA[Basics
Thunderbird messages can be composed from the command line, and the syntax is pretty basic (field=&#8217;value&#8217;).  For Example:
admin@box:$ thunderbird &#8211;compose &#8220;to=&#8217;foo@bar.com,bar@foo.com&#8217;,subject=&#8217;nice tip&#8217;,attachment=&#8217;file:///home/admin/tip.txt&#8217;,body=&#8217;Check out this neat command line tip&#8217;&#8221;

Caveats: 
Values don&#8217;t have to be in single quotes. However, if you have multiple values or characters that might be interpreted by Thunderbird, as actually being part [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight: bold;">Basics</span><br />
Thunderbird messages can be composed from the command line, and the syntax is pretty basic (field=&#8217;value&#8217;).  For Example:<br />
<span style="font-family:courier new;">admin@box:$ thunderbird &#8211;compose &#8220;to=&#8217;foo@bar.com,bar@foo.com&#8217;,subject=&#8217;nice tip&#8217;,attachment=&#8217;file:///home/admin/tip.txt&#8217;,body=&#8217;Check out this neat command line tip&#8217;</span>&#8221;<br />
<span style="font-weight: bold;"><br />
Caveats: </span><br />
Values don&#8217;t have to be in single quotes. However, if you have multiple values or characters that might be interpreted by Thunderbird, as actually being part of the command, you will get results you may not have intended.  So, put the whole part after<span style="font-style: italic;"> </span><span><span style="font-family:courier new;">&#8211;compose</span></span> in double quotes and use single quotes for the values.  You also need to make sure that there are no spaces after or before the commas that separate the field value pairs (Basically anything outside of the single quotes). Lastly, this is not entirely from the command line.  The Thunderbird compose email window will pop up with the fields populated, so you can edit them and then send it.<br />
<span style="font-weight: bold;"><br />
Tip:</span><br />
This can be combined with command substitution.  So if you want to email a file to someone with the contents of a file in the body of the message and not as an attachment you can do the following:<br />
<span style="font-family:courier new;">admin@box:$ thunderbird &#8211;compose &#8220;to=&#8217;foo@bar.com&#8217;,subject=&#8217;I sent this message using command substitution&#8217;,body=&#8217;$(cat file.txt)&#8217;&#8221;</span></p>
<p>You can now enjoy having some of the power of the command line in your email while still just using a simple gui application.<br />
<span style="font-size:78%;"><br />
</span><span style="font-size:78%;">Reference:<br />
<a href="http://www.mozilla.org/docs/command-line-args.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.mozilla.org/docs/command-line-args.html');">http://www.mozilla.org/docs/command-line-args.html</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kbrandt.com/2008/05/quick-tip-tunderbird-email-from-command.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Batch Convert Multiple Bin/Cue files to Iso Files in Linux</title>
		<link>http://www.kbrandt.com/2007/07/batch-convert-multiple-bincue-files-to.html</link>
		<comments>http://www.kbrandt.com/2007/07/batch-convert-multiple-bincue-files-to.html#comments</comments>
		<pubDate>Tue, 24 Jul 2007 23:17:00 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bin files]]></category>
		<category><![CDATA[cue files]]></category>

		<guid isPermaLink="false">http://www.kbrandt.com/?p=15</guid>
		<description><![CDATA[I had a bunch of bin/cue disk image files that I needed to convert to .iso files, and the program bchunk didn&#8217;t seem to have any way to process multiple files that I could see.  So I came up with a command that would do this for me, so if you need to do [...]]]></description>
			<content:encoded><![CDATA[<p>I had a bunch of <a href="http://en.wikipedia.org/wiki/Bin_cue#.BIN.2F.CUE" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://en.wikipedia.org/wiki/Bin_cue#.BIN.2F.CUE');">bin/cue</a> disk image files that I needed to convert to .iso files, and the program <a href="http://he.fi/bchunk/" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://he.fi/bchunk/');">bchunk</a> didn&#8217;t seem to have any way to process multiple files that I could see.  So I came up with a command that would do this for me, so if you need to do the same:</p>
<ol>
<li>Install bchunk: In Ubuntu you can get it by: sudo apt-get install bchunk</li>
<li>Navigate to the directory that has your bin/cue file pairs that you want to convert.</li>
<li>You can convert them all to iso files with the following command, assuming all your bin/cue file pairs have the same root file name, and the extensions are all lowercase: for i in *.cue; do bchunk ${i/.cue}.bin ${i/.cue}.cue ${i/.cue}.iso; done</li>
<li>That should be it, hope this helps someone out.  Anyone have a better way?</li>
</ol>
<p>I will explain how this works for people trying to learn a little bit more about the command line.  The bchunk command takes three arguments, and normally would look like &#8220;bchunk foo.bin foo.cue. foo.iso&#8221;. The command is a <a href="http://en.wikipedia.org/wiki/For_loop" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://en.wikipedia.org/wiki/For_loop');">for loop</a>, and everything between &#8220;do&#8221; and the the last semicolon gets repeated as a whole unit for as many times as there are cue files in the current directory (This would be the <span style="font-style: italic;">loop body</span>).  The variable i represents each .cue file for each time the loop body is run.  &#8220;${i/.cue}&#8221; strips the file name of its extension (So really &#8220;${i/.cue}.cue&#8221; is redundant) and the extension that bchunk expects is added with what follows the curly braces.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kbrandt.com/2007/07/batch-convert-multiple-bincue-files-to.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
