Saturday, March 27, 2010

What is Shell Scripting?

  Shell script is nothing but a batch file of windows.  In layman's term, a set of UNIX commands put together in a file becomes a shell script. In addition, the shell also provides additional programming  logic handling thereby making it more useful.

  Shell scripting or programming is typically used when we want to automate tasks which we do repeatedly. Once a shell script is created for a task or activity, just the script needs to be run in order to perform the task from next time onwards. Undoubtedly, shell script saves lot of time for the end user.

  A good Shell programmer is one who has a very good grip on the UNIX command line interface. A Shell programmer with not a good knowledge of UNIX command line will end up writing big scripts, which actually could have been done using some UNIX commands itself.

Let's  see how to write a simple shell script to display the 'Hello World' :

1. Write a script file with the following contents as shown below:

    # cat
       echo "Hello World"

 2.  Give executable permission to the file:

   #chmod u+x

 3. Run the script:

   Hello World

The following things are to be noted:

1. The first line '/usr/bin/ksh' tells in which shell this script should be run.
2. This line is not mandatory. If this line is not present, the script will be run by the default shell of the user.
3. Every script should be given the executable permission in order to execute it.
4. ./ tells the shell that the script '' to be executed is present in the current directory.

 'Happy scripting'.
Related Posts Plugin for WordPress, Blogger...

No comments:

Post a Comment