BASH is an acronym for Bourne Again Shell.
Bash is a shell program written by Brian Fox as an upgraded version of Bourne Shell program ‘sh’.
Bash is the default login shell for most Linux distributions and Apple’s mac OS.
There are different types of shells available in Linux Operating Systems.Some are,
- Bourne Shell
- C shell
- Korn Shell
- GNU Bourne Shell
To know where bash is located in your OS, type the below command.
which bash
cat /etc/shells
Hello World! Bash Script
- Open any editor in you Linux machine
- create file with .sh extension
- Then Code Your Script
echo “ Hello World! “
4.change the file into executable mode
chmod +x path/filename.sh
5.Compile and Execute the file using the below command
./filename.sh
Bash Comments
Bash Single Line Command
#single line command.it doesn’t execute
<<COMMENT Multiple Line Command COMMENT
Bash Variables
Variables are the containers which store data as the value inside them.
The variables are accessed using Dollar Symbol ( $ )
Syntax
Variable_name =value
Example
- year=2012
- comp_name=Kongunadu
Types of Bash Variables
1.System-Defined Variables
These are the pre-defined variables as they are created and maintained by the LINUX operating system itself.
example :#! /bin/bash
# Bash System-defined Variables
echo $HOME # Home Directory
echo $PWD # current working directory
echo $BASH # Bash shell name
echo $BASH_VERSION # Bash shell Version
echo $LOGNAME # Name of the Login Use
echo $OSTYPE # Type of OS
2.User-Defined Variables
These variables are created and maintained by the user.
Read User Input
To read the Bash user input, we use the built-in Bash command called read.
Syntax
read <variable_name>
read -p “username:” user_var
echo “The username is: “ $user_var
Bash Date Formatting
Bash shell provides different date commands along with different formatting options. We can use those commands to format Bash date to a required one.
date #This Command display the current date in the System
For More Commands refer this tutorials
https://www.javatpoint.com/bash-date-format
Bash Sleep
Syntax
sleep number[suffix]
Examples
- sleep 9 or sleep 9s
- sleep 0.5 or sleep 0.5s
- sleep 2m 30s
- sleep 8h
- sleep 2d 9h 5m 55s
Thank You !!!
Charge and Update the Brain and Knowledge in Daily Basis