🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 36 (from laksa145)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

📄
INDEXABLE
✅
CRAWLED
18 hours ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.linuxfordevices.com/tutorials/shell-script/for-loop-in-shell-scripts
Last Crawled2026-04-07 00:27:41 (18 hours ago)
First Indexed2020-03-11 12:11:41 (6 years ago)
HTTP Status Code200
Meta TitleShell Scripting 101: The for Loop in Shell Scripts - LinuxForDevices
Meta DescriptionMoving ahead with our tutorials now, let's introduce the for loop in shell scripts in our today's topic. We've already covered the while loop in our previous
Meta Canonicalnull
Boilerpipe Text
Moving ahead with our tutorials now, let’s introduce the for loop in shell scripts in our today’s topic. We’ve already covered the while loop in our previous tutorial and used the break and continue statements to quit the while loop based on certain conditions. Let’s get right into the topic then! What’s The Difference Between while Loop and for Loop in Shell Scripts? The major difference between for loop and while loop is in their definition and syntax. When working with the while loop, we provide one condition that the while loop continues to loop on until it turns false. We do not specify the number of iterations for the loop. On the other hand, for loop takes 2 or 3 conditions and the last condition usually decides the number of iterations. The first condition is the variable that iterates through a sequence when the loop begins and increments automatically based on what it’s iterating over. For example, if it has to run over a sequence of numbers, the variable increments itself based on the numbers supplied to it. If everything I wrote above sounded like gibberish to you, just continue reading and everything will become crystal clear soon. Definition of the Bash for loop There are two ways you can define the bash for loop. The first is the bash style with two variables, and the second is C style with 3 variables. Here’s the syntax for both of them. Bash Style for loop definition: for VARIABLE in SEQUENCE The VARIABLE is the variable name to use within the loop, and the SEQUENCE is anything ranging from a sequence of numbers, multiple files, Linux commands, etc. C Style for loop definition: for (( variable declaration; condition; increment variable)) How to Use the for Loop? Now that you have a basic understanding of the for loop , it’s time to start using it in our scripts. We’ll start by creating a simple for loop that iterates over a given sequence of numbers. #!/bin/bash for i in 1 2 3 4 5 6 7 do echo "Loop number $i" done For Loop In Shell Scripts Very simple to understand? Let’s move on to a different sequence group. Bash For Loop Over Files The for loop doesn’t read the contents of the file when we loop over it but just allows us to perform operations on individual files while looping over them. Let’s see an example below. #!/bin/bash for i in *.txt do echo "Contents from the files: $i" cat $i done For Loop Iterate Over Files I’ve created two files with some text in them for demonstration purposes. See how I write the cat command once and the for loop iterates over both the files. Writing C Style for Loops in Shell Scripts You should be comfortable with iterating over individual sequences now. Let’s move on to the C style for loops that we talked about before. If you’ve already worked with C or C++, this is going to be almost the same thing. But even if you haven’t it’s not too difficult. Let’s create a for loop that iterates 7 times and echos the number. for (( i=1; i<=7; i++ )) do echo "Loop number $i" done C Style For Loop Let’s understand the loop section by section. The reason why we use the double parenthesis is to signal bash that we’re using a C style expression within the brackets. The first expression: i=1 creates the start of the loop. The second expression: i<=7 tells that the loop should run until the variable is lesser than or equal to 7 The last expression: i++ decides how the increment happens. In this case, it happens by 1 Conclusion I hope this helps you understand how the for loop in shell scripts works. Feel free to comment below for any questions that you may have.
Markdown
[Skip to content](https://www.linuxfordevices.com/tutorials/shell-script/for-loop-in-shell-scripts#content) [![Linux](https://www.linuxfordevices.com/wp-content/uploads/2021/01/linux.svg)](https://www.linuxfordevices.com/) Main Menu - [Home](https://www.linuxfordevices.com/) - [About](https://www.linuxfordevices.com/about) - [Contact Us](https://www.linuxfordevices.com/contact-me) - [Privacy Policy](https://www.linuxfordevices.com/privacy-policy-2) # Shell Scripting 101: The for Loop in Shell Scripts By [Ninad Pathak](https://www.linuxfordevices.com/author/ninad "View all posts by Ninad Pathak") / March 3, 2020 ![For Loop](https://www.linuxfordevices.com/wp-content/uploads/2020/02/for-loop-1024x768.png) Moving ahead with our tutorials now, let’s introduce the for loop in shell scripts in our today’s topic. We’ve already covered the [while loop](https://www.linuxfordevices.com/tutorials/shell-script/while-loop-in-shell-script) in our previous tutorial and used the [break and continue statements](https://www.linuxfordevices.com/tutorials/shell-script/break-and-continue-statement-in-linux-shell-script) to quit the while loop based on certain conditions. Let’s get right into the topic then\! ## What’s The Difference Between while Loop and for Loop in Shell Scripts? **The major difference between for loop and while loop is in their definition and syntax.** When working with the while loop, we provide one condition that the while loop continues to loop on until it turns false. We do not specify the number of iterations for the loop. On the other hand, for loop takes 2 or 3 conditions and the last condition usually decides the number of iterations. The first condition is the variable that iterates through a sequence when the loop begins and increments automatically based on what it’s iterating over. For example, if it has to run over a sequence of numbers, the variable increments itself based on the numbers supplied to it. If everything I wrote above sounded like gibberish to you, just continue reading and everything will become crystal clear soon. ## Definition of the Bash for loop There are two ways you can define the bash for loop. The first is the bash style with two variables, and the second is C style with 3 variables. Here’s the syntax for both of them. **Bash Style for loop definition:** ``` for VARIABLE in SEQUENCE ``` The **VARIABLE** is the variable name to use within the loop, and the **SEQUENCE** is anything ranging from a sequence of numbers, multiple files, Linux commands, etc. **C Style for loop definition:** ``` for (( variable declaration; condition; increment variable)) ``` ## How to Use the for Loop? Now that you have a basic understanding of the **for loop**, it’s time to start using it in our scripts. We’ll start by creating a simple for loop that iterates over a given sequence of numbers. ``` #!/bin/bash for i in 1 2 3 4 5 6 7 do echo "Loop number $i" done ``` ![For Loop In Shell Scripts](https://www.linuxfordevices.com/wp-content/uploads/2020/02/for-loop-in-bash.png) For Loop In Shell Scripts Very simple to understand? Let’s move on to a different sequence group. ### Bash For Loop Over Files The for loop doesn’t read the contents of the file when we loop over it but just allows us to perform operations on individual files while looping over them. Let’s see an example below. ``` #!/bin/bash for i in *.txt do echo "Contents from the files: $i" cat $i done ``` ![For Loop Iterate Over Files](https://www.linuxfordevices.com/wp-content/uploads/2020/02/for-loop-iterate-over-files.png) For Loop Iterate Over Files I’ve created two files with some text in them for demonstration purposes. See how I write the [cat command](https://www.linuxfordevices.com/tutorials/linux/cat-more-command-in-linux) once and the for loop iterates over both the files. ### Writing C Style for Loops in Shell Scripts You should be comfortable with iterating over individual sequences now. Let’s move on to the C style for loops that we talked about before. If you’ve already worked with C or C++, this is going to be almost the same thing. But even if you haven’t it’s not too difficult. Let’s create a for loop that iterates 7 times and echos the number. ``` for (( i=1; i<=7; i++ )) do echo "Loop number $i" done ``` ![C Style For Loop](https://www.linuxfordevices.com/wp-content/uploads/2020/02/c-style-for-loop.png) C Style For Loop Let’s understand the loop section by section. The reason why we use the double parenthesis is to signal bash that we’re using a C style expression within the brackets. - The first expression: **i=1** creates the start of the loop. - The second expression: **i\<=7** tells that the loop should run until the variable is lesser than or equal to 7 - The last expression: **i++** decides how the increment happens. In this case, it happens by 1 ## Conclusion I hope this helps you understand how the for loop in shell scripts works. Feel free to comment below for any questions that you may have. [← Previous Post](https://www.linuxfordevices.com/tutorials/shell-script/if-else-in-shell-script "Shell Scripting 101: If Else in Shell Script") [Next Post →](https://www.linuxfordevices.com/tutorials/shell-script/switch-case-in-shell-scripts "Shell Scripting 101: Switch Case in Shell Scripts") ## Recent Posts - [How to Install Kali Linux in VirtualBox: Complete Setup Guide](https://www.linuxfordevices.com/tutorials/kali-linux/install-kali-linux-in-virtualbox) - [Kali Linux Commands: Essential Guide for Penetration Testing](https://www.linuxfordevices.com/tutorials/kali-linux/kali-linux-commands) - [Types of Shell in Linux: Understanding Your Command Line Options](https://www.linuxfordevices.com/tutorials/linux/types-of-shell-in-linux) - [The Linux wget Command – Linux Download Command](https://www.linuxfordevices.com/tutorials/linux/linux-wget-command) - [How to Install LM Studio – Step-by-Step Guide (2025)](https://www.linuxfordevices.com/tutorials/how-to-install-lm-studio-step-by-step-guide-2025) ## Favorite Sites - [Python Tutorials](https://www.askpython.com/) - [GoLang Tutorials](https://golangdocs.com/) - [CodeForGeek](https://codeforgeek.com/) - [VM-Help](https://www.vm-help.com/) - [MySQL Tutorials](https://mysqlcode.com/) - [Excel Tutorials](https://quickexcel.com/) ![Linuxlogo](https://www.linuxfordevices.com/wp-content/uploads/2024/10/linuxlogo.png) Learn everything about Linux, under a single roof. LinuxForDevices covers Linux tutorials, Open Source news, and courses to help you grow. Copyright © 2026 · LinuxForDevices · LinuxForDevices is part of Diyansh IT Services Private Limited Linux® is a registered trademark of Linus Torvalds.
Readable Markdown
Moving ahead with our tutorials now, let’s introduce the for loop in shell scripts in our today’s topic. We’ve already covered the [while loop](https://www.linuxfordevices.com/tutorials/shell-script/while-loop-in-shell-script) in our previous tutorial and used the [break and continue statements](https://www.linuxfordevices.com/tutorials/shell-script/break-and-continue-statement-in-linux-shell-script) to quit the while loop based on certain conditions. Let’s get right into the topic then\! ## What’s The Difference Between while Loop and for Loop in Shell Scripts? **The major difference between for loop and while loop is in their definition and syntax.** When working with the while loop, we provide one condition that the while loop continues to loop on until it turns false. We do not specify the number of iterations for the loop. On the other hand, for loop takes 2 or 3 conditions and the last condition usually decides the number of iterations. The first condition is the variable that iterates through a sequence when the loop begins and increments automatically based on what it’s iterating over. For example, if it has to run over a sequence of numbers, the variable increments itself based on the numbers supplied to it. If everything I wrote above sounded like gibberish to you, just continue reading and everything will become crystal clear soon. ## Definition of the Bash for loop There are two ways you can define the bash for loop. The first is the bash style with two variables, and the second is C style with 3 variables. Here’s the syntax for both of them. **Bash Style for loop definition:** ``` for VARIABLE in SEQUENCE ``` The **VARIABLE** is the variable name to use within the loop, and the **SEQUENCE** is anything ranging from a sequence of numbers, multiple files, Linux commands, etc. **C Style for loop definition:** ``` for (( variable declaration; condition; increment variable)) ``` ## How to Use the for Loop? Now that you have a basic understanding of the **for loop**, it’s time to start using it in our scripts. We’ll start by creating a simple for loop that iterates over a given sequence of numbers. ``` #!/bin/bash for i in 1 2 3 4 5 6 7 do echo "Loop number $i" done ``` ![For Loop In Shell Scripts](https://www.linuxfordevices.com/wp-content/uploads/2020/02/for-loop-in-bash.png) For Loop In Shell Scripts Very simple to understand? Let’s move on to a different sequence group. ### Bash For Loop Over Files The for loop doesn’t read the contents of the file when we loop over it but just allows us to perform operations on individual files while looping over them. Let’s see an example below. ``` #!/bin/bash for i in *.txt do echo "Contents from the files: $i" cat $i done ``` ![For Loop Iterate Over Files](https://www.linuxfordevices.com/wp-content/uploads/2020/02/for-loop-iterate-over-files.png) For Loop Iterate Over Files I’ve created two files with some text in them for demonstration purposes. See how I write the [cat command](https://www.linuxfordevices.com/tutorials/linux/cat-more-command-in-linux) once and the for loop iterates over both the files. ### Writing C Style for Loops in Shell Scripts You should be comfortable with iterating over individual sequences now. Let’s move on to the C style for loops that we talked about before. If you’ve already worked with C or C++, this is going to be almost the same thing. But even if you haven’t it’s not too difficult. Let’s create a for loop that iterates 7 times and echos the number. ``` for (( i=1; i<=7; i++ )) do echo "Loop number $i" done ``` ![C Style For Loop](https://www.linuxfordevices.com/wp-content/uploads/2020/02/c-style-for-loop.png) C Style For Loop Let’s understand the loop section by section. The reason why we use the double parenthesis is to signal bash that we’re using a C style expression within the brackets. - The first expression: **i=1** creates the start of the loop. - The second expression: **i\<=7** tells that the loop should run until the variable is lesser than or equal to 7 - The last expression: **i++** decides how the increment happens. In this case, it happens by 1 ## Conclusion I hope this helps you understand how the for loop in shell scripts works. Feel free to comment below for any questions that you may have.
Shard36 (laksa)
Root Hash11864324050110837636
Unparsed URLcom,linuxfordevices!www,/tutorials/shell-script/for-loop-in-shell-scripts s443