<?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>Lindesk &#187; Opinion</title>
	<atom:link href="http://lindesk.com/tag/opinion/feed/" rel="self" type="application/rss+xml" />
	<link>http://lindesk.com</link>
	<description>Linux - on the Desktop</description>
	<lastBuildDate>Tue, 23 Jun 2009 14:03:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Shell Script Language &#8211; Use Perl, Not Bash</title>
		<link>http://lindesk.com/2008/05/shell-script-language-use-perl-not-bash/</link>
		<comments>http://lindesk.com/2008/05/shell-script-language-use-perl-not-bash/#comments</comments>
		<pubDate>Fri, 02 May 2008 18:22:17 +0000</pubDate>
		<dc:creator>BinnyVA</dc:creator>
				<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://lindesk.com/?p=107</guid>
		<description><![CDATA[
To me, a shell script is a script that automates repetitive tasks. But that is not the &#8216;official&#8217; definition. Wikipedia has this definition&#8230;
A shell script is a script written for the shell, or command line interpreter, of an operating system.
I use a definition that defines the purpose of the script &#8211; while the others prefer [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://lindesk.com/wp-content/uploads/2008/02/terminal.png'><img src="http://lindesk.com/wp-content/uploads/2008/02/terminal.png" alt="" title="Terminal" width="128" height="128" class="alignnone intro size-full wp-image-96" align="right" /></a></p>
<p class="intro">To me, a shell script is a <strong class="highlight">script that automates repetitive tasks</strong>. But that is not the &#8216;official&#8217; definition. Wikipedia has this <a href="http://en.wikipedia.org/wiki/Shell_scripts">definition</a>&#8230;</p>
<blockquote cite="http://en.wikipedia.org/wiki/Shell_scripts"><p>A shell script is a script written for the shell, or command line interpreter, of an operating system.</p></blockquote>
<p>I use a definition that <strong class="highlight">defines the purpose</strong> of the script &#8211; while the others prefer a definition that <strong class="highlight">defines the technology used</strong>. I am not going to claim that my definition is better than the other definition &#8211; that&#8217;s pointless. Besides, even I think that the &#8216;other&#8217; definition is the right one. But I will try to show you the advantages of my approach.</p>
<h2>The Purpose</h2>
<p>I like to automate things(in other words, I&#8217;m lazy). So I have a nice little collection of custom shell scripts. But there is a huge barrier to writing shell scripts &#8211; the language used. <strong class="highlight">Traditionally shell scripts are written in a language provided by the shell</strong> &#8211; like <a href="http://www.gnu.org/software/bash/bash.html">bash</a> or <a href="http://www.tcsh.org/Welcome">tcsh</a>. That is the problem &#8211; these languages are Bad &#8211; with a capital &#8216;B&#8217;.</p>
<h2>The Problem</h2>
<p>To people who are accustomed to decent languages, these <strong class="highlight">shell languages will seem clunky</strong> &#8211; or even evil. But since most shell scripts are small, most people don&#8217;t mind the torture.</p>
<p>In bash, the control flow commands seem to be thrown in as a after thought rather than something that&#8217;s built into the language. If you don&#8217;t believe me, compare the &#8216;if&#8217; loop of bash and Perl.</p>
<h3>Bash</h3>
<p>This code checks wether the variable &#8216;$value&#8217; has the value 0 &#8211; if so it prints the message &#8216;No Value&#8217;</p>
<pre><code class="bash">if [ $value -eq 0 ] ; then
	echo "No Value"
fi</code></pre>
<h3>Perl</h3>
<p>The same code in Perl&#8230;</p>
<pre><code class="perl">if($value == 0) {
	print "No Value";
}</code></pre>
<p>Of course, Perl experts will go for <code>if(!$value)</code> or even <code>unless($value)</code> &#8211; but that&#8217;s not the point. See how better the <strong class="highlight">code looks in Perl</strong>. Yeah, even I am surprised to hear those words &#8211; Perl is considered by many to be an &#8216;ugly&#8217; language. But when compared to shell languages, Perl is a gem(sorry about the pun &#8211; couldn&#8217;t resist).</p>
<h2>The Solution</h2>
<p>The solution is simple &#8211; <strong class="highlight">don&#8217;t use a shell language to write your shell scripts &#8211; use a high level scripting language</strong> like Perl. Or Python, Ruby, PHP, Tcl or <a href="http://www.openjs.com/articles/javascript_scripting_language.php">even JavaScript</a>.</p>
<p>I still use <a href="http://www.openjs.com/articles/javascript_scripting_language.php" title="Command Line Twitter Client">bash to write shell scripts</a> &#8211; but if the shell script has an if condition(other than a simple argument check), I use a higher language &#8211; usually Perl.</p>
<h2>Advantages of using a Shell Language</h2>
<ul>
<li>Its supported in even the tinest linux distros &#8211; even in embedded systems.</li>
<li>Its the method preferred by the majority &#8211; I hope this will change soon.</li>
<li>Command calls look more natural in a shell language.</li>
</ul>
<h2>Advantages of using a High Level Language</h2>
<ul>
<li>Better Code</li>
<li>Easy to maintain</li>
<li>Faster development</li>
<li>Libraries provide a lot of functionality</li>
<li>Easier to port to different platforms.</li>
</ul>
<p>So why am I telling you all this? Two reasons&#8230;</p>
<p>One, the next time you are going to write a shell script, I want you to choose a high level language rather than using bash.</p>
<p>The second reason is that now that <a href="http://lindesk.com/2008/03/top-10-linux-mp3-players/">my series on Linux MP3 Players</a> are over, I am going to take a small break from desktop posts and write on more &#8216;linuxy&#8217; topics. And one of those topic is Shell Scripting. So in the future posts, I am going to share some of my shell scripts with you. So when I publish a Perl script and call it a shell script, I don&#8217;t want you to get confused .</p>
]]></content:encoded>
			<wfw:commentRss>http://lindesk.com/2008/05/shell-script-language-use-perl-not-bash/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
	</channel>
</rss>
