Introduction:
for loop is one of the most used control flow statements in any scripting or programming language, if you want to do some task using bash shell that is repetitive, you can make use of for loop in bash, let's see some examples,
Syntax:for variable_name in 1 2 3 4 .. n
do
command/statement 1
command/statement 2
...
...
command/statement n
done
#!/bin/bash
#Mutiplication Table of Two
no=2
for num in 1 2 3 4 5 6 7 8 9 10
do
echo $(($num*$no))
done
Example:
#!/bin/bash
#Mutiplication Table of Two
no=2
for num in {1..10}
do
echo $(($num*$no))
done
Syntax:
for (( initializer; condition; step ))
do
command/statement
...
command/statement
done
Example:
#!/bin/bash
#Mutiplication Table of Two
no=2
for (( i=1; i<=10; i++ ))
do
echo $(($i*$no))
done

-
Have Questions? Post them here!
More Posts related to Bash,
- How to start or open a new bourne-again shell (bash) session on Windows using Command Line CMD
- How to create new user account in Windows bash
- Bash Hello World! Script Tutorial
- How to Compare Strings in Bash
- How to see Created Accessed Modified and Changed dates of a file using bash terminal command
- Command to Sort File In Reverse Order [Unix/Linux/macOS]
- Bash command to wait for seconds
- [fix] bash: ssh: command not found
- bash: netstat: command not found
- Know Bash shell version command
- List all Username and User ID using Bash Command
- How to use Autocomplete and Autosuggestion in Shell Commands
- How to know the current shell you are logged in?
- [Fix] bash: script.sh: /bin/bash^M: bad interpreter: No such file or directory
- 'pwd' is not recognized as an internal or external command, operable program or batch file. [Windows]
- How to Kill a port using bash terminal command?
- How to fix bash ping command not found error
- Install Bash Completion on macOS
- bash get year 2021 calendar
- How to check your IP using bash for Windows?
- Bash For Loop Example
- Fix bash: script.sh: Permission denied Error
More Posts:
- Docker - Error response from daemon: You cannot remove a running container - Docker
- How to disable Microsoft teams from startup Windows 10 - Teams
- How to turn off Stage Manager - macOS Ventura - MacOS
- Clear Screen shortcut macOS Terminal - MacOS
- macOS: Change Weather App Temperature unit from Fahrenheit to Degree - MacOS
- Java: The value of the local variable string is not used - Java
- [Error] There was an error connecting to the apple id server - HowTos
- Get Device Screen Width and Height using javaScript - JavaScript