Back to Wiki Shell Scripting

Shell Scripting -Introduction to Shell Scripting

HINTechnologies Admin 23 Sep 2026

HINTechnologies – Introduction to Shell Scripting

Category: Linux & Shell Scripting Training

HINTechnologies — Learn More and Earn More

Day 1 – Introduction to Shell Scripting

Course: Linux & Shell Scripting Training Level: Beginner to Advanced Focus: Shell, Bash, Shell Scripts, Execution and Basic Commands

Day 1 Objectives

By the end of Day 1, students should be able to:

  1. Understand what a Shell is.
  2. Understand what Shell Scripting is and why it is used.
  3. Identify common Linux shells.
  4. Understand Bash and its role in Linux automation.
  5. Create a basic Shell script.
  6. Understand the Shebang (#!).
  7. Give execution permission to a script.
  8. Execute a script using different methods.
  9. Use Linux commands inside a Shell script.
  10. Use command substitution.
  11. Add comments and structure scripts clearly.

1. What is a Shell?

A Shell is a command-line interpreter that provides an interface between the user and the operating system.

Basic Flow

User
  |
  v
Terminal
  |
  v
Shell
  |
  v
Linux Kernel
  |
  v
Hardware

The Shell accepts commands from the user, interprets them, communicates with the Linux operating system, and displays the result.

Common Shells

  • sh
  • bash
  • ksh
  • csh
  • zsh
  • fish

In this course, the primary focus is Bash.

2. What is Shell Scripting?

Shell scripting is the process of writing a sequence of Shell commands inside a text file so that the commands can be executed automatically.

A Shell script is normally saved with a .sh extension.

Example:

hello.sh

Simple Shell Script

#!/bin/bash

echo "Hello HINTechnologies"
echo "Welcome to Shell Scripting"

Shell Scripting is Used For

  • Automating repetitive tasks
  • Server administration
  • Log processing
  • Backup automation
  • Monitoring
  • Deployment automation
  • Application support
  • DevOps workflows
  • CI/CD automation
  • Production operations

3. Why Do We Need Shell Scripting?

Suppose an administrator needs to check the following on a server:

  • Disk usage
  • Memory usage
  • CPU/load
  • Server uptime
  • Running services
  • Application status

Without scripting, the administrator may execute several commands manually:

df -h
free -m
uptime
systemctl status nginx

A Shell script can combine these commands and execute them as one automated process:

#!/bin/bash

df -h
free -m
uptime
systemctl status nginx

The main advantage is automation.

Instead of repeatedly typing commands, we write the commands once and execute the script whenever required.

4. What is Bash?

BASH = Bourne Again Shell

Bash is one of the most widely used Shells on Linux systems and is commonly used for Linux administration, automation and DevOps.

Check Bash Version

bash --version

Check Current Shell

echo $SHELL

Check Available Shells

cat /etc/shells

Bash is the primary Shell used throughout this training.

5. Shell vs Shell Script

Shell

A Shell is an interpreter/environment used to execute commands.

Example:

bash

Shell Script

A Shell script is a file containing a sequence of commands.

Example:

server_info.sh

Example

Command:

date

Script:

#!/bin/bash

date
hostname
whoami

A script allows multiple commands to be grouped and automated.

6. Creating Your First Shell Script

Create a file:

vi hello.sh

or:

nano hello.sh

Example content:

#!/bin/bash

echo "Hello HINTechnologies"
echo "Welcome to Shell Scripting"
date
hostname
whoami

Check the content:

cat hello.sh

7. Shebang

The first line of a Bash script is commonly:

#!/bin/bash

This is called the Shebang.

It tells the operating system which interpreter should be used to execute the script.

Structure

#! + interpreter path

Examples

#!/bin/bash
#!/bin/sh
#!/usr/bin/python3

For this training, use:

#!/bin/bash

8. Script Permissions

After creating a script, check its permissions:

ls -l hello.sh

A newly created script may not have execute permission.

Give execute permission:

chmod +x hello.sh

Check again:

ls -l hello.sh

Then execute:

./hello.sh

Another common way to execute it is:

bash hello.sh

9. Different Ways to Execute a Script

Method 1 – Execute Directly

./hello.sh

This normally requires execute permission and uses the interpreter specified by the Shebang.

Method 2 – Execute Using Bash

bash hello.sh

This explicitly starts Bash to execute the script.

Important Interview Question

What is the difference between ./script.sh and bash script.sh?

./script.sh:

  • Requires execute permission.
  • Normally follows the interpreter specified by the Shebang.

bash script.sh:

  • Bash is explicitly used to interpret the…

Keep Reading With Full Access

This is a preview. Enrolled students get full access to every article on our Wiki — apply for a course to unlock the rest of this one and everything else we publish.