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

syntax:
chmod permission your-script-name

Example:
$ 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

syntax:
bash your-script-name
sh your-script-name
./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
pwd
echo The date is
date
echo calendar
cal

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:

clear
echo -e “33[31m calendar”
cal

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

http://www.freeos.com/guides/lsst/misc.htm

Advertisements

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: