'Bash' Shell Scripting

I have started learning bash scripting so thought to pen down my learning journey

Day 1 - Getting to know Bash

Before getting into 'what is bash?' let's first understand the concept about SHELLS

So what is a shell?

  • Shell is the set of programs that act as a link or interface between the user and Kernel (It is a central component of an operating system that manages operations of computers and hardware).
  • Whenever we type in a command at the terminal the shell interprets the command and calls the program which we want.
  • This makes it interpreted not complied so basically it's a CLI ( command-line interpreter)

Let's take an example - Whenever a user logs in, the login program checks the username and password then it starts another program

image.png

So, there are different types of shells like C Shell (csh), The Bourne Shell (sh), Bash, etc and Bash is one of Unix shells.

Standard practice whenever writing the first line of bash script is to write shebang or hashbang

To print statements in bash we use Echo command-

#!/bin/bash
echo "Hey, Guys!"

Shell script should have executable permissions (e.g. -rwx r-x r-x)

Using Variables and Comments

We write "#" for bash comments

There are two types of variables in bash -

System Variables - These are the predefined variables and are written in capital cases like $BASH,$PWD, $HOME, etc.

#!/bin/bash
echo $BASH

User-defined Variables- These are defined by us users and it is majorly written in lower cases but also in upper case.

#!/bin/bash
name=Sam
echo The name is $name

Read user INPUT -

We use the command called read which is a bash built-in command that reads a line from the standard input

#!/bin/bash
echo "Enter name:"
read name
echo "The name entered is $name"

Did you find this article valuable?

Support Samruddhi Wasu by becoming a sponsor. Any amount is appreciated!