<?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>Mark Needham &#187; Shell Scripting</title>
	<atom:link href="http://www.markhneedham.com/blog/category/shell-scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markhneedham.com/blog</link>
	<description>Thoughts on Software Development</description>
	<lastBuildDate>Sat, 31 Jul 2010 07:06:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Browsing around the Unix shell more easily</title>
		<link>http://www.markhneedham.com/blog/2008/10/15/browsing-around-the-unix-shell-more-easily/</link>
		<comments>http://www.markhneedham.com/blog/2008/10/15/browsing-around-the-unix-shell-more-easily/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 12:31:16 +0000</pubDate>
		<dc:creator>Mark Needham</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=498</guid>
		<description><![CDATA[Following on from my post about getting the pwd to display on the bash prompt all the time I have learnt a couple of other tricks to make the shell experience more productive. Aliases are the first new concept I came across and several members of my current team and I now have these setup. [...]]]></description>
			<content:encoded><![CDATA[<p>Following on from my post about getting the <a href="http://www.markhneedham.com/blog/2008/09/28/show-pwd-all-the-time/">pwd to display on the bash prompt all the time</a> I have learnt a couple of other tricks to make the shell experience more productive.</p>
<p><a href="http://en.wikipedia.org/wiki/Unalias#Removing_aliases_.28unalias.29">Aliases</a> are the first new concept I came across and several members of my current team and I now have these setup.</p>
<p>We are primarily using them to provide a shortcut command to get to various locations in the file system. For example I have the following 'work' alias in my ~/.bash_profile file:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">alias work='cd ~/path/to/my/current/project'</pre></div></div>

<p>I can then go to the bash prompt and type 'work' and it navigates straight there. You can put as many different aliases as you want in there, just don't forget to execute the following command after adding new ones to get them reflected in the current shell:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">. ~/.bash_profile</pre></div></div>

<p>A very simple idea but one that helps save so many keystrokes for me every day.</p>
<p>Another couple of cool commands I recently discovered are <strong>pushd</strong> and <strong>popd</strong></p>
<p>They help provide a stack to store directories on, which I have found particularly useful when browsing between distant directories.</p>
<p>For example suppose I am in the directory '/Users/mneedham/Desktop/Blog/' but I want to go to '/Users/mneedham/Projects/Ruby/path/to/some/code' to take a look at some code.</p>
<p>Before changing to that directory I can execute:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">pushd .</pre></div></div>

<p>This will push the current directory ('/Users/mneedham/Desktop/Blog/') onto the stack. Then once I'm done I just need to run:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">popd</pre></div></div>

<p>I'm back to '/Users/mneedham/Desktop/Blog/' with a lot less typing.</p>
<p>Running the following command shows a list of the directories currently on the stack:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">dirs</pre></div></div>

<p>I love navigating with the shell so if you've get any other useful tips please share them!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.markhneedham.com/blog/2008/10/15/browsing-around-the-unix-shell-more-easily/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Show pwd all the time</title>
		<link>http://www.markhneedham.com/blog/2008/09/28/show-pwd-all-the-time/</link>
		<comments>http://www.markhneedham.com/blog/2008/09/28/show-pwd-all-the-time/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 12:50:44 +0000</pubDate>
		<dc:creator>Mark Needham</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[pwd]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=390</guid>
		<description><![CDATA[Finally back in the world of the shell last week I was constantly typing 'pwd' to work out where exactly I was in the file system until my colleague pointed out that you can adjust your settings to get this to show up automatically for you on the left hand side of the prompt. To [...]]]></description>
			<content:encoded><![CDATA[<p>Finally back in the world of the shell last week I was constantly typing 'pwd' to work out where exactly I was in the file system until my colleague pointed out that you can adjust your settings to get this to show up automatically for you on the left hand side of the prompt.</p>
<p>To do this you need to create or edit your .bash_profile file by entering the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">vi ~/.bash_profile</pre></div></div>

<p>Then add the following line to this file:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">export PS1='\u@\H \w\$ '</pre></div></div>

<p>You should now see something like the following on your command prompt:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">mneedham@Macintosh-5.local /users/mneedham/Erlang/playbox$</pre></div></div>

<p>Another colleague pointed out that the information on the left side is completely configurable. The following entry from the manual pages of bash (Type 'man bash' then search for 'PROMPTING') show how to do this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">PROMPTING
       When executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command.  Bash allows these prompt
       strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows:
              \a     an ASCII bell character (07)
              \d     the date in &quot;Weekday Month Date&quot; format (e.g., &quot;Tue May 26&quot;)
              \D{format}
                     the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation.  The braces are required
              \e     an ASCII escape character (033)
              \h     the hostname up to the first `.'
              \H     the hostname
              \j     the number of jobs currently managed by the shell
              \l     the basename of the shell's terminal device name
              \n     newline
              \r     carriage return
              \s     the name of the shell, the basename of $0 (the portion following the final slash)
              \t     the current time in 24-hour HH:MM:SS format
              \T     the current time in 12-hour HH:MM:SS format
              \@     the current time in 12-hour am/pm format
              \A     the current time in 24-hour HH:MM format
              \u     the username of the current user
              \v     the version of bash (e.g., 2.00)
              \V     the release of bash, version + patchelvel (e.g., 2.00.0)
              \w     the current working directory
              \W     the basename of the current working directory
              \!     the history number of this command
              \#     the command number of this command
              \$     if the effective UID is 0, a #, otherwise a $
              \nnn   the character corresponding to the octal number nnn
              \\     a backslash
              \[     begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
              \]     end a sequence of non-printing characters</pre></div></div>

<p><a href="http://www.faqs.org/docs/abs/HTML/files.html"> This page</a> has more information on some of the other files that come in useful when shell scripting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.markhneedham.com/blog/2008/09/28/show-pwd-all-the-time/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
