<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: ksh code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 07:53:50 GMT</pubDate>
    <description>DZone Snippets: ksh code</description>
    <item>
      <title>add a folder to PATH, but not if it is already in PATH</title>
      <link>http://snippets.dzone.com/posts/show/4821</link>
      <description>Often times one uses a single .profile or .bashrc across several hosts.  These hosts may be differently configured, with varying directory locations, and different initial PATH values from /etc/profile.  In situations like this, setting PATH the traditional way -- "PATH=$PATH:/path/to/some/stuff" -- can result in a cumbersomely long PATH that includes inaccessible or duplicate folders.  &lt;br /&gt;&lt;br /&gt;The snippet below nicely handles this problem.  It has been tested on Solaris and Linux.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;AddPath ()&lt;br /&gt;# Add argument to $PATH if:&lt;br /&gt;# - it is not already present&lt;br /&gt;# - it is a directory&lt;br /&gt;# - we have execute permission on it&lt;br /&gt;#&lt;br /&gt;# This snippet is public domain; you may use it freely.  Death to copyright, patents, &lt;br /&gt;# and all other forms of intellectual monopoly.  &lt;br /&gt;#&lt;br /&gt;{&lt;br /&gt;  _folder=$1&lt;br /&gt;  echo " $PATH " | sed 's/:/ /g' | grep " $_folder " &gt; /dev/null&lt;br /&gt;  [ $? -ne 0 ] &amp;&amp; [ -d $_folder ] &amp;&amp; [ -x $_folder ] &amp;&amp; PATH=$PATH:$_folder&lt;br /&gt;  export PATH&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;# Add some common paths:&lt;br /&gt;AddPath /usr/bin&lt;br /&gt;AddPath /usr/local/bin&lt;br /&gt;AddPath /opt/somepackage/bin&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 28 Nov 2007 18:38:16 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4821</guid>
      <author>jmcvetta (Jason McVetta)</author>
    </item>
    <item>
      <title>bash aliases</title>
      <link>http://snippets.dzone.com/posts/show/1991</link>
      <description>For old duffers like me who were used to earlier shells when bash came along.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# These save typing, I use them a lot&lt;br /&gt;&lt;br /&gt;alias sd='cd -' &gt; /dev/null&lt;br /&gt;alias cx='chmod +x'&lt;br /&gt;alias which="type -path"&lt;br /&gt;&lt;br /&gt;# This goes back to Unix v7, some time around 1985 I think.&lt;br /&gt;&lt;br /&gt;alias lf='ls -CF'&lt;br /&gt;&lt;br /&gt;# From my 'C' shell days. Those were almost 20 years ago as well. Sigh.&lt;br /&gt;&lt;br /&gt;alias h='fc -l -20'&lt;br /&gt;alias r='fc -s'&lt;br /&gt;&lt;br /&gt;# Because real men use 'vi' and why use character mode if you have X?&lt;br /&gt;&lt;br /&gt;alias vi='gvim'&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 06 May 2006 02:31:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1991</guid>
      <author>mikewilsonuk (Mike Wilson)</author>
    </item>
    <item>
      <title>.inputrc to make bash command-line editing like ksh</title>
      <link>http://snippets.dzone.com/posts/show/1990</link>
      <description>I was used to ksh and vi when bash came along, so I wanted the behaviour to remain the same. Some may think this odd.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;set editing-mode vi&lt;br /&gt;set keymap vi&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 06 May 2006 02:26:24 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1990</guid>
      <author>mikewilsonuk (Mike Wilson)</author>
    </item>
    <item>
      <title>Basename in ksh without using /usr/bin/basename</title>
      <link>http://snippets.dzone.com/posts/show/818</link>
      <description>Faster than $( basename ) or `basename`&lt;br /&gt;&lt;code&gt;BASENAME=${0##*/}&lt;/code&gt;</description>
      <pubDate>Tue, 18 Oct 2005 23:53:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/818</guid>
      <author>jones77 (James Jones)</author>
    </item>
  </channel>
</rss>
