Category: Linux & Shell Scripting Training
HINTechnologies — Learn More and Earn More
Course: Linux & Shell Scripting Training Level: Beginner to Advanced Focus: Shell, Bash, Shell Scripts, Execution and Basic Commands
By the end of Day 1, students should be able to:
#!).A Shell is a command-line interpreter that provides an interface between the user and the operating system.
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.
shbashkshcshzshfishIn this course, the primary focus is Bash.
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
#!/bin/bash
echo "Hello HINTechnologies"
echo "Welcome to Shell Scripting"
Suppose an administrator needs to check the following on a server:
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.
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.
bash --version
echo $SHELL
cat /etc/shells
Bash is the primary Shell used throughout this training.
A Shell is an interpreter/environment used to execute commands.
Example:
bash
A Shell script is a file containing a sequence of commands.
Example:
server_info.sh
Command:
date
Script:
#!/bin/bash
date
hostname
whoami
A script allows multiple commands to be grouped and automated.
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
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.
#! + interpreter path
#!/bin/bash
#!/bin/sh
#!/usr/bin/python3
For this training, use:
#!/bin/bash
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
./hello.sh
This normally requires execute permission and uses the interpreter specified by the Shebang.
bash hello.sh
This explicitly starts Bash to execute the script.
What is the difference between ./script.sh and bash script.sh?
./script.sh:
bash script.sh:
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.