Thoughts on Programming

August 8, 2011

Shell Scripting

Filed under: Linux — shadiyya @ 10:28 am

Shell scripts combine lengthy and repetitive sequences of commands and generalize a sequence of operations on one set of data.

Following steps are required to write shell script:

(1) Use any editor like vi to write shell script.

(2) After writing shell script set execute permission for your script as follows

chmod permission your-script-name

$ chmod 755 your-script-name

This will set read write execute(7) permission for owner, for group and other – permission is read and execute only(5).

(3) Execute your script as

bash your-script-name
sh your-script-name

Following is an example of a very simple shell script

echo You are
who am i
echo The directory you are in is
echo The date is
echo calendar

It will print the user’s name, current directory, date & time and calendar of this month.

Now, we can color this output on the screen, by the following code word :

echo -e “33[31m This is in Red”

Now, to get a red colored calendar, we can use the following code:

echo -e “33[31m calendar”

There are many more interesting features in shells. Some detailed informations are available here:


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at

%d bloggers like this: