Bash Shell Scripting:- Lesson 7,8 &9 for DevOps Engineers.

Bash Shell Scripting:- Lesson 7,8 &9 for DevOps Engineers.

Dear Learners, In Today Topic, We will learn the Shell Scripting form Basics to Advanced for DevOps Engineers.

Course Content:

Lesson 7:- Bash Shell Scripting Nested IF Condition in Shell Script.

Lesson 8:- Bash Shell Scripting Using Logical and Operator in Shell Script.

Lesson 9:- Bash Shell Scripting Using Logical OR Operator in Shell Script.

IMP We are Dividing the Terminal in 2 Parts Right Side Script Execution and Left Side Write a bash file with Syntax.

Lesson 7:- Bash Shell Scripting Nested IF Condition in Shell Script.

Nested IF function means one if function inside the another allows you to multiple criteria and increase the Number of possible outcomes.

Let us discuss with the help of practical:-

To check the file is available or not:-

output:- does not exist

we are executing the script with read permissions, write permission.
#!/bin/bash
# Nested IF Condition in shell Scripts"

echo -e "Please Enter the name of file \c"

read filename
# to check the file is available or not
if [ -f $filename ]
then
        if [ -w $filename ]
        then
            echo "please type your test here & press ctrl+d to exit"
                cat >> $filename
                else
         echo "$filename does not have the write permission on it"
                fi
else
        echo "$filename does not exists"
fi
        
Article content
To check the file is available or not:-

To check if file is available in system and Append the Text.

we are executing the script with read permissions, write permission.
#!/bin/bash
# Nested IF Condition in shell Scripts"

echo -e "Please Enter the name of file \c"

read filename
# to check the file is available or not
if [ -f $filename ]
then
        if [ -w $filename ]
        then
            echo "please type your test here & press ctrl+d to exit"
                cat >> $filename
                else
         echo "$filename does not have the write permission on it"
                fi
else
        echo "$filename does not exists"
fi
        
Article content
To check if file is available in system and Append the Text Diagram.

Lesson 8:- Bash Shell Scripting Using Logical AND Operator in Shell Script.

Logical AND Operator in shell operator:-

If the both conditions are high and the equal to each other we will get the output for ex:- 1 = 1

Logical AND Operators
Input    output
X Y        Z
0 0        0
0 1        0
1 0        0
1 1        1        
if the age is valid        
Let us discuss with the help of age example.
age will be greater than 18 or age will be less than 40
Synatx:-
#!/bin/bash
# Logical AND Operator &&in shell Scripts"

echo -e "Please Enter the age \c"
read age
if [ "$age" -gt 18 ] && [ "$age" -lt 40 ]
then
echo "age is valid"
else
echo "age is not valid"
fi        

if the age is not valid

et us discuss with the help of age example.
age will be greater than 18 or age will be less than 40
Synatx:-
#!/bin/bash
# Logical AND Operator &&in shell Scripts"

echo -e "Please Enter the age \c"
read age
if [ "$age" -gt 18 ] && [ "$age" -lt 40 ]
then
echo "age is valid"
else
echo "age is not valid"
fi        
Article content
if the age is not valid Diagram.

Lesson 9:- Bash Shell Scripting Using Logical OR Operator in Shell Script.

In this lecture we will discuss the logical OR operator how to implement in shell scripting to define the different different conditions.

it is used to define the either the one condition is true system will not go to the second. if ones work it will execute if 1st wrong it will move to the second.        

for example:- compare the the 2 commands:-

cal || zdate
zdate || cal        
Article content
for example:- compare the the 2 commands Diagraml

Let us discuss with the help of Script:-

Compare the Age in these Script.
if the age is less than 18 || greater than 40 
        
#!/bin/bash
# Logical OR  Operator &&in shell Scripts"
echo -e "please enter the age: /c"
read age

if [ "$age" -lt 18 ] || [ "$age" -gt  40 ]
then
        echo "age is valid true"
else
        echo "age is not valid"


fi
        
Article content
if the age is less than 18 || greater than 40 diagram

Another Method You are Execute the Script with the help -o with single Quotes.


#!/bin/bash
# Logical OR  Operator &&in shell Scripts"
echo -e "please enter the age: /c"
read age

if [ "$age" -le 18 -o  "$age" -ge  40 ] 
then
        echo "age is valid true"
else
        echo "age is not valid"


fi

        
Article content
Another Method You are Execute the Script with the help -o with single Quotes Diagram.

Hope I helped you in understanding the concept in a better way!!

Happy Learning !!

To view or add a comment, sign in

More articles by Maninder Singh

  • Artificial Intelligence for DevOps Engineer

    Dear learners, In today article we will explain the Artificial Intelligence for the DevOps Engineers. Important Aspects…

    12 Comments
  • Bash Shell Scripting:- Lesson 4,5 &6 for DevOps Engineers.

    Dear Learners, In Today Topic, We will learn the Shell Scripting form Basics to Advanced for DevOps Engineers. Course…

    3 Comments
  • Bash Shell Scripting:- Lesson 1,2 &3 for DevOps Engineers.

    Dear Learners, In Today Topic, We will learn the Shell Scripting form Basics to Advanced for DevOps Engineers. Course…

    3 Comments
  • EP 2 DevOps:- 2 Tier Application Deployment

    2-Tier Application Deployment Diagram (Architecture) Dear Learners in today topic we will deploy a 2 Tier Application…

    8 Comments
  • DevOps Engineers:- Docker Cheat Sheet

    Dear learner, presented below is a concise yet comprehensive Docker cheat sheet, complete with detailed commands and…

    7 Comments
  • DevOps (Day-90): Ending the challengs

    Table of Contents: Flashback Self-Impact of Learning Today, We have completed the 90days of DevOps challenge where we…

    16 Comments
  • DevOps (Day-88): Kubernetes Architecture

    Dear Learner's in today topic we will discuss the Kubernetes Architecture in detail. Table of Contents Kubernetes…

    1 Comment
  • DevOps (Day-87): Argo CD

    Dear Learners in today topic we will the discuss the Argo CD in Kubernetes. Table of Contents Challenges with CD into…

    13 Comments
  • DevOps (Day-86): Project-7 Portfolio App

    Dear Learners in Today's article we will deploying a Portfolio app on AWS S3 Bucket using GitHub. Table of Contents:…

    10 Comments
  • DevOps (Day-85): Project-6 Utilizing AWS ECS Fargate and ECR with a Node JS app

    Dear Learners In Today Article we will explain the Deploying a Node JS app with the help of AWS ECS Fargate and AWS…

    8 Comments

Explore content categories