What is Shell Scripting...Explained!


Shell scripting is a method to use the shell efficiently. First, I shall explain what a shell is, well, Shell is a piece of software that provides an interface for users.
Typically, the term refers to an operating system shell which provides access to the services of a kernel. However, the term is also applied very loosely to applications and may include any software that is "built around" a particular component, such as web browsers and email clients that are "shells" for HTML rendering engines. The name 'shell' originates from shells being an outer layer of interface between the user and the innards of the operating system (the kernel).

Now a days, the term shell is generally used for command line interface of an operating system. Ex. Bash (Linux), Command Prompt (Windows), etc. But often its used for unix or linux shell.

Normally shells are interactive. It means shell accept command from you (via keyboard) and execute them. But if you use command one by one (sequence of 'n' number of commands) , the you can store this sequence of command to text file and tell the shell to execute this text file instead of entering the commands. This is known as shell script.

So, in short, a shell script is a sequence of commands which is packed as a executable file.

Features of shell scripts are:

  • Shell script can take input from user, file and output them on screen.
  • Useful to create our own commands.
  • Save lots of time.
  • To automate some task of day today life.
  • System Administration part can be also automated.

The craft of scripting is not hard to master, since the scripts can be built in bite-sized sections and there is only a fairly small set of shell-specific operators and options to learn. The syntax is simple and straightforward, similar to that of invoking and chaining together utilities at the command line, and there are only a few "rules" governing their use. Most short scripts work right the first time, and debugging even the longer ones is straightforward.

A working knowledge of shell scripting is essential to anyone wishing to become reasonably proficient at system administration, even if they do not anticipate ever having to actually write a script. Consider that as a Linux machine boots up, it executes the shell scripts in /etc/rc.d to restore the system configuration and set up services. A detailed understanding of these startup scripts is important for analyzing the behavior of a system, and possibly modifying it.

I am not going to provide you a tutorial on shell scripting. You can find lots of them on the internet. The basic purpose of this article is to explain what shell and shell scripting is.

Following is an example of a shell script...

#!/bin/sh
# This is a comment!
echo Hello World

Explanation of example:

The first line tells Unix that the file is to be executed by /bin/sh. This is the standard location of the Bourne shell on just about every Unix system. If you're using GNU/Linux, /bin/sh is normally a symbolic link to bash.

The second line begins with a special symbol: #. This marks the line as a comment, and it is ignored completely by the shell.

The third line runs a command: echo, with two parameters, or arguments - the first is "Hello"; the second is "World".

-------------------------------------------------------------------------------------------------------------

Did you like this post? Do you have any questions or suggestions? Please post a comment.


Subscribe via Email:

Subscribe in a reader

1 comments:

Shubham NeO ©® said...

Awesome post bro... loved it !

Post a Comment

All of your comments are most welcome. Do not post spam...