0% found this document useful (0 votes)
58 views

Bash While Loop Statement - Syntax and Examples

Uploaded by

ludipova
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Bash While Loop Statement - Syntax and Examples

Uploaded by

ludipova
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

10/1/2021 Bash While Loop Statement - Syntax and Examples

⊖ Bash Shell
Scripting
SAP  Salesforce  Programming  Tools  Informatica
✦ Bash Tutorial

✦ Bash Script
Example Bash While Loop Statement
✦ Bash File
Extension
– Syntax and Examples
✦ Bash Echo

✦ Bash Comments

✦ Bash Variable

✦ Bash Command
Line Arguments

✦ Bash Read User


Input

✦ Bash Read
Password

✦ Bash Date Format

✦ Bash Sleep
Bash While Loop
⊖ Operators

✦ Bash Arithmetic Bash While Loop is a loop statement used to


Operators execute a block of statements repeatedly
based on the boolean result of an expression,
⊖ Conditional
Statements for as long as the expression evaluates to
TRUE.
✦ Bash If

✦ Bash If Else

✦ Bash Else If
Syntax of Bash While Loop
✦ Bash Case

⊖ Loops
while [ expression ]; do
✦ Bash For Loop statements;
multiple statements;
Bash While Loop
done
✦ Bash Until Loop

⊖ Strings The expression can contain only one


condition. If the expression should have
✦ Bash String
https://www.tutorialkart.com/bash-shell-scripting/bash-while-loop/ 1/5
10/1/2021 Bash While Loop Statement - Syntax and Examples

multiple conditions, the syntax of while loop


⊖ Bash Shell is as follows :
Scripting

✦ Bash Tutorial
while [[ expression ]]; do
✦ Bash Script
statements;
Example
multiple statements;
✦ Bash File done
Extension

✦ Bash Echo

✦ Bash Comments
Example of bash while loop
✦ Bash Variable

✦ Bash Command Following is an while loop with only multiple


Line Arguments
conditions in expression.
✦ Bash Read User
Input bash-while-loop-example

✦ Bash Read
Password #!/bin/bash

✦ Bash Date Format


count=10
✦ Bash Sleep i=0

⊖ Operators # while loop


while [ $i -lt $count ]; do
✦ Bash Arithmetic
echo "$i"
Operators
let i++
done
⊖ Conditional
Statements

✦ Bash If

✦ Bash If Else

✦ Bash Else If

✦ Bash Case

⊖ Loops

✦ Bash For Loop

Bash While Loop

✦ Bash Until Loop

⊖ Strings When the above while loop script is run in


terminal,
✦ Bash String
https://www.tutorialkart.com/bash-shell-scripting/bash-while-loop/ 2/5
10/1/2021 Bash While Loop Statement - Syntax and Examples

Shell Script Terminal Output


⊖ Bash Shell
Scripting arjun@arjun-VPCEH26EN:~/workspace/bash$ ./b
0
✦ Bash Tutorial 1
✦ Bash Script 2
Example 3
4
✦ Bash File
5
Extension
6
✦ Bash Echo 7
8
✦ Bash Comments
9
✦ Bash Variable

✦ Bash Command
Line Arguments

✦ Bash Read User Example of while loop – multiple


Input
conditions in expression
✦ Bash Read
Password bash-while-loop-example-2

✦ Bash Date Format


#!/bin/bash
✦ Bash Sleep

⊖ Operators count=10
a=0
✦ Bash Arithmetic b=0
Operators
# multiple conditions in the expression of
⊖ Conditional while loop
Statements while [[ $a -lt $count && $b -lt 4 ]]; do
echo "$a"
✦ Bash If
let a++
✦ Bash If Else let b++
✦ Bash Else If done

✦ Bash Case
Run the above while loop script in terminal,
⊖ Loops

✦ Bash For Loop Shell Script Terminal Output

Bash While Loop arjun@arjun-VPCEH26EN:~/workspace/bash$ ./b


0
✦ Bash Until Loop
1

⊖ Strings 2
3
✦ Bash String
https://www.tutorialkart.com/bash-shell-scripting/bash-while-loop/ 3/5
10/1/2021 Bash While Loop Statement - Syntax and Examples

⊖ Bash Shell
Scripting To realize looping in bash, we have bash for
loop  along with while loop.
✦ Bash Tutorial

✦ Bash Script
Example

✦ Bash File Conclusion :


Extension
In this Bash Tutorial – Bash While Loop, we
✦ Bash Echo
have learnt about syntax of while loop
✦ Bash Comments
statement in bash scripting for single and
✦ Bash Variable
multiple conditions in expression with example
✦ Bash Command
scripts.
Line Arguments

✦ Bash Read User


Input

✦ Bash Read
Password

✦ Bash Date Format

✦ Bash Sleep

⊖ Operators

✦ Bash Arithmetic
Operators ❮ Previous Next ❯

⊖ Conditional
Statements
 Download Bash While Loop
✦ Bash If
Statement - Syntax and Examples in
✦ Bash If Else PDF
✦ Bash Else If

✦ Bash Case
Most Read Articles
⊖ Loops

✦ Bash For Loop What extension is given to a Bash Script File?

Bash While Loop


Learn about For Loop in Bash Scripting
✦ Bash Until Loop

How to check if a Bash Variable is Set?


⊖ Strings

✦ Bash String
https://www.tutorialkart.com/bash-shell-scripting/bash-while-loop/ 4/5
10/1/2021 Bash While Loop Statement - Syntax and Examples

Bash Else If with Lots of Examples


⊖ Bash Shell
Scripting
Bash way of writing Single and Multiline
✦ Bash Tutorial
Comments
✦ Bash Script
Example How to Split a String in Bash Scripting?
✦ Bash File
Extension

Popular
✦ Bash Echo Interview Tutorial Kart
✦ Bash Comments
Tutorials Questions ➤ About Us
✦ Bash Variable
➤ Salesforce Tutorial ➤ Salesforce Visualforce ➤ Contact Us
✦ Bash Command
➤ SAP Tutorials Interview Questions ➤ Careers - Write for us
Line Arguments
➤ Kafka Tutorial ➤ Salesforce Apex ➤ Privacy Policy
✦ Bash Read User
➤ Kotlin Tutorial Interview Questions ➤ Terms of Use
Input
➤ Kotlin Interview ✎ Write Us Feedback
✦ Bash Read
Password
Questions
  
✦ Bash Date Format

✦ Bash Sleep
www.tutorialkart.com - ©Copyright-TutorialKart 2018

⊖ Operators

✦ Bash Arithmetic
Operators

⊖ Conditional
Statements

✦ Bash If

✦ Bash If Else

✦ Bash Else If

✦ Bash Case

⊖ Loops

✦ Bash For Loop

Bash While Loop

✦ Bash Until Loop

⊖ Strings

✦ Bash String
https://www.tutorialkart.com/bash-shell-scripting/bash-while-loop/ 5/5

You might also like