<?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>Bin-Blog &#187; scripting</title>
	<atom:link href="http://www.bin-co.com/blog/tag/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bin-co.com/blog</link>
	<description>Learn about the latest in Web Development - as soon as I do.</description>
	<lastBuildDate>Tue, 13 Oct 2009 18:55:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Hello Script for bash</title>
		<link>http://www.bin-co.com/blog/2008/05/hello-script-for-bash/</link>
		<comments>http://www.bin-co.com/blog/2008/05/hello-script-for-bash/#comments</comments>
		<pubDate>Mon, 12 May 2008 18:02:25 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[hello]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/?p=107</guid>
		<description><![CDATA[Hello Script series for Bash. &#8216;Hello Script&#8217; is a file that contains the most commonly used elements of a programming language so that it can be used as a cheat sheet when working with that language.
bash
bash is the most commonly used shell in Linux. That makes the bash scripting language the most popular shell scripting [...]]]></description>
			<content:encoded><![CDATA[<p class="intro"><a href="http://www.bin-co.com/blog/2008/03/learning-a-new-programming-language-the-hello-world-method/">Hello Script series</a> for Bash. <strong>&#8216;Hello Script&#8217; is a file that contains the most commonly used elements of a programming language so that it can be used as a cheat sheet</strong> when working with that language.</p>
<h2>bash</h2>
<p><a href="http://www.gnu.org/software/bash/">bash</a> is the most commonly used shell in Linux. That makes the bash scripting language the most popular shell scripting language. OK, maybe after batch. But then again, bash is much more powerful than batch(DOS scripting language). If want to learn bash, I will recommend this tutorial &#8211; <a href="http://tldp.org/LDP/abs/html/">Advanced Bash Scripting</a></p>
<p>Officially, <a href="http://lindesk.com/2008/05/shell-script-language-use-perl-not-bash/">I hate bash</a>. I use perl or other similar high level language to create shell script. I use bash only for the <a href="http://binnyva.blogspot.com/2007/03/using-twitter-part-1-command-line.html">simplest scripts</a>. But even I admit that bash has its uses. So, here is the hello script for bash&#8230;</p>
<h2>Hello Script</h2>
<pre><code class="bash">
#!/usr/sh

# Printing(IO)
echo "Hello World"

# Variables, concatenation
name='Binny'
year=2008
echo "Hello, " $name " - welcome to " $year

#If,else conditions
if [ $year -gt 2008 ]; then
	echo "Welcome to the future - yes, we have flying cars!"

elif [ $year -lt 2008 ]; then
	echo "The past - please don't change anything. Don't step on any butterflies. And for the sake of all that's good and holy, stay away from your parents!"

else
	echo "Anything wrong with your time machine? You have not gone anywhere, kiddo."
fi

# If you are using anything after this, consider using a high level language.
# For loop
for i in 1 2 3
do
	echo $i ") Hi there!"
done

#Numerical Array, foreach
rules[0]="Do no harm"
rules[1]="Obey"
rules[2]="Continue Living"

for ((i=0; i &lt; 3; i++))
do
	echo "Rule" `expr $i + 1` ":" ${rules[$i]}
done

#A While Demo
keys=(hello foo lorem)

i=0
while [ $i -lt 3 ]
do
	echo ${keys[$i]}
	i=`expr $i + 1`
done

# Function, argument, return, call
hello () {
	myname=$1  #First argument.
	echo "Hello" $myname
}
hello "Binny"

# File IO
# File reading
contents=`cat Hello.sh` #For some reason, I'm losing all the \n's in the file.
echo "Hello has `echo $contents|wc -m` chars" # Or wc -m Hello.sh

# Writing to a file
echo "Hello World from shell script" &gt; /tmp/hello.txt

# Command Executing
ls

# Regular Expressions
string="Hello World"
evil=`echo $string | grep '^Hell'`
if [ "$evil" != "" ]; then
	echo "Yup - its evil"
fi
echo "Hello World" | sed -e 's/l//g' #Will return Heo Word

# http://tldp.org/LDP/abs/html/
</code></pre>
<p>And, by the way, this will work only in Linux &#8211; or if you installed cygwin in your Windows system. Use <code>sh &lt;File_Name&gt;</code> to execute the above code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2008/05/hello-script-for-bash/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
