Shell Scripting

·

3 min read

Most of us want to know what are this shell and scripting. Let's dive in to understand the difference.

Shell - It is a program that takes the command as input. It will give those commands to the operating system to execute. Shell is the interface between the user and the operating system.

Scripting - This will help to automate the tasks.

How Many Shells do we have Linux?

  1. sh bash - Default shell.

  2. ksh - default in AIX. AIX is the OS of IBM.

  3. bash - Bonue Again Shell.

  4. csh - C shell.

What is Shell Scripting now?

It is a simple text file with a series of Linux commands. Normally Shell Scripting has an extension .sh but again it's not mandatory to have the extension. It's always a good practice that we save the file extension as per the extension format for that scripting language or programming language. In this case, it would be .sh.

How to know which shell is supported by your OS?

How to display the current shell that we are using?

What is the shebang line in Shell Scripting?

the shebang line is the first line where the Shell Scripting begins. Again it's not mandatory to use but as per the best practice method it's good that we write the script with the shebang line as a first.

Ex: #!/bin/bash

Following are the steps required to write Shell Script:

  1. Using any editor open the file i.e vi <File-Name. sh>

  2. After writing the Shell Script, give the execute permission - Chmod <permission> <File-Name.sh>

  3. Execute your script as - sh <File-Name.sh>

Example: Let's write a script to display today's date with the good morning message.

Now after understanding why Shell Scripting, now your question would be why we need to use it, and how it will help me.

Patience!

Definitely, you are putting effort to learn Shell Scripting which means definitely there is a huge use for it.

Let's say I want to schedule the job which monitors my system resources and sends an email once it hit the maximum usage. If you are doing it manually, you might forget to do/check which leads to a huge crunch in system resources and loss of business or users might face accessing the site. Here doing automation would help us to understand the situation at regular intervals and act accordingly whenever we see the huge usage of the system.

One more example would be taking a backup of your database at regular intervals or days/weeks.

With the understanding of the usage of Shell Scripting and writing one simple script to, can I execute the script in debug mode?

Why not, you can execute the script in debug mode.

sh -x <File-Name.sh>

- x - is the option that provides us to execute the code in debug mode.

Try the above option and post your message in the comment box with the output.

Please follow me for more information about the DevOps Topic and tools with detailed examples and usage.

If you have any feedback, you can send it to .