DEV Community

Susmita Dey
Susmita Dey

Posted on

Getting Started With Shell Scripting(Shell Programming)

What is a Shell?

A shell is a command line tool in Linux/Unix operating systems. It processes the command entered by the user and interprets into machine-readable binary form that can be understood by the Kernel to carry out the process.


What is Kernel?

The kernel is a computer program at the core of a computer's operating system and generally has complete control over everything in the system. It is the portion of the operating system code that is always resident in memory, and facilitates interactions between hardware and software components.

  • Source: Wikipedia

image.png

This picture is taken from GeeksForGeeks website.


What is a Shell Script?

A shell script is a computer program designed to be run by the Unix shell, a command-line interpreter.

  • Source: Wikipedia

We write shell script with the help of a special program called terminal of the Operating System. Terminal looks similar to the Command Prompt or Windows Powershell of Windows Operating System.


Types of Shell

There are various types of shell in Linux.
Some of them are as follows -

  1. Bourne Shell
  2. C Shell
  3. Korn Shell
  4. Bourne Again Shell

Shell Prompt

$ sign in the terminal is known as the Shell Prompt.


Using Shell in Windows

For Windows users, you can do any of the following -

  1. Set up your computer for dual boot - containing both Windows and Ubuntu together.
  2. Install the virtual box in your computer containing the Linux OS. image.png
  3. Use Windows Subsystem for Linux( WSL) by installing it.
  4. Otherwise, you can use a Browser extension named OnWorks to run Ubuntu or Kali Linux online.

OnWorks Extension

OnWorks extension works on Firefox and Chrome Browsers. It acts as an emulator for the windows system creating the ISO image of the chosen OS to run it online.

image.png

  • Benefit of using this extension is that you can use any OS you like to run online and all are free to use. Also, you can save your work in your Google Drive.
  • Disadvantage of using it is that if you leave the tab inactive for more than 10 minutes, then you have to run the OS again as it logs you out from the session automatically. So, sometimes you might get irritated.

Writing Our First Shell Script

  1. Search for terminal in the search bar
  2. Open your terminal
  3. Type gedit <filename>.sh and then hit Enter.

For example:-
image.png

  1. Then you'll see a text editor opens up with the file name like this - image.png
  2. Now, we're are ready to write our code.
echo "Hello World"
Enter fullscreen mode Exit fullscreen mode
  1. Now save the file and open a new terminal.
  2. Type bash <filename>.sh. Here, bash hello.sh.
  3. Now hit Enter to see the output. image.png

Congratulations 🎉 You have written your first shell script program.

You can also watch this video for clarity.


Hope this helps you. Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my YouTube Channel and connect on LinkedIn or Twitter.
Also, feel free to support my work.😊

Top comments (0)