Web Application Penetration Testing Tutorial For Beginners

Shell Scripting Tutorial: Full Guide to With Basics & Cool Scripts to Learn Shell Scripting

What is Shell Scripting?

Shell scripting is the process of writing a program to offer users an interface where they can use the functions of an OS by running the commands. The role of these commands is to perform particular tasks. 

BASH or Bourne Again Shell is the most preferred shell which is used for shell scripting. It comes by default in the majority of Linux systems. 

Test your knowledge with a quick quiz!

Shell scripting is used on which operating system.

Select the correct answer

Uses of Shell Scripting

Generally, shell scripting is used to avoid repetitive tasks. Scripts can be written for the purpose of automating a number of instructions that are supposed to be done or executed one by one, rather than writing commands for each task.  It is also used by DevOps teams and backend developers. 

Intro to Shell Scripting

Intro to Shell Scripting

Test your knowledge with a quick quiz!

grep is used for __________________

Select the correct answer

Learning Basics of Shell Scripting

Let’s understand the basics of shell scripting with a simple example.

Here is a common script:

#!/bin/bash

echo "Welcome!! Write Your First Name"

read first name

echo "Hello $first name"

Let’s divide this code into multiple parts:

  • #!/bin/bash

The role of #! Is to trigger the operating system and tell it which interpreter to choose for file execution. For instance, there are multiple shell interpreters, such as csh (C shell), sss (secure shell), ksh, zsh (macOS). 

The line of code used here will tell the system to go with the bash interpreter. 

  • echo "Welcome!! Write Your First Name"

The role of echo is to show the output for the strings that are passed as arguments. 

  • Read first name

The read command’s role in shell scripting is to fetch the input when the script is being run. For example, the read command here will start a variable whose name is first name. It will then store the input into this variable. 

  • echo "Hello $first name"

Lastly, the role of the $ symbol here is to print the variable’s value. For instance, here, it will print the first name defined in the previous step.

Writing Cool Scripts

Writing Cool Scripts

It’s Quiz Time!

quiz-img
Did you find this article helpful?