Bash Scripting

Bash Scripting

Day 01 Basic Fundaments of Bash Script

·

2 min read

What is Bash scripting

Bash stands for Bourne Again Shell. A Bash Shell Script is a plain text file containing a set of various commands that we usually type in the command line. It is used to automate repetitive tasks on Linux. To automate day-to-day automation tasks, system admins write bash scripts in the Linux system. Bash script has a .sh extension but the extension is not mandatory.

What is Shell

A Shell is a command-line interpreter between the user and kernel or a complete environment specially designed to run commands, shell scripts, and programs.

Advantages of Shell Script

  • Easy to use

  • Time-saving

  • Automated

  • Can be installed on all Linux system

  • Portable

  • Can run multiple commands

Disadvantages of Shell Script

  • There may be errors in shell scripting that prove to be quite costly.

  • The programs in shell script are quite slow while executing and a new process is required for every shell command executed.

  • Different platforms in shell scripting may also have compatibility problems.

First Bash script

Bash script starts with #! referred to as the shebang followed by /bin/bash it tells the path of the interpreter to execute the commands in the script.

echo: echo is a built-in command in Bash, which is used to display the standard output by passing the arguments. It is the most widely used command for printing the lines of text/String to the screen.

To Run bash use

 bash script_name.sh
 OR
./script_name.sh

Script to print Hello Wrld!

#!/bin/bash
echo "******************"
echo "Hello World!"
echo "******************"

After execution

image

Single line comment in bash use [#]

image

After execution

image

Multiple line comments in bash use [: ' commented text ']

image

After execution

image