Shell Scripting-
Shell scripting is writing a series of commands in a file that a computer can execute automatically. It helps you automate repetitive tasks and manage system operations more efficiently.
For create shell scripting file use shell commands-(any text editor)
The echo
command is used to display messages on the terminal. It's a simple yet powerful tool for outputting text and variables.
#!/bin/bash
echo "Hello my name is Gayatri"
echo "This is my first reposirory for shell scripting"
echo "Day01"
Basic scripting skills-
Variables
#!/bin/bash
<< comment
anything
written
here
comment
name="jetha"
echo "Name is $name, and date is $(date)"
echo "Enter the name:"
read username
echo "You entered $username"
echo "The characters in $0 is $1 and $2"
Arguments
#!/bin/bash
read -p "Enter username:" username
echo "You Entered $username"
sudo useradd -m $username
echo "New User added"
conditions if else elif
#!/bin/bash
<< desclaimer
This is for infotainment purpose
desclaimer
read -p "Jetha ne mud ke kise dekha: " bandi
read -p "Jetha ka pyar %:" pyar
if [[ $bandi == "Daya bhabhi" ]];
then
echo "Jetha is Loyal"
elif [[ $pyar -ge 100 ]];
then
echo "jetha is Loyal"
else
echo "Jetha is not Loyal"
fi
Loop -for
#!/bin/bash
#This is for loop
<< comment
1 is argument 1 which is folder name
2 is start range
3 is end range
comment
for ((num=$2; num<=$3; num++))
do
mkdir "$1$num"
done
functions
#!/bin/bash
<< desclaimer
This is for infotainment purpose
desclaimer
#This is function definition
function is_loyal() {
read -p "Jetha ne mud ke kise dekha: " bandi
read -p "Jetha ka pyar %:" pyar
if [[ $bandi == "Daya bhabhi" ]];
then
echo "Jetha is Loyal"
elif [[ $pyar -ge 100 ]];
then
echo "jetha is Loyal"
else
echo "Jetha is not Loyal"
fi
}
#This is function call
is_loyal
ย