🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 67 (from laksa152)

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
8 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.3 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.unixmen.com/bash-for-loop-a-complete-guide-for-perfect-scripts/
Last Crawled2026-04-04 11:10:26 (8 days ago)
First Indexed2024-06-06 09:48:39 (1 year ago)
HTTP Status Code200
Meta TitleBash For Loop: A Complete Guide for Perfect Scripts | Unixmen
Meta DescriptionBash for loop—an extremely helpful control statement in Bash scripting—is just this article away from learning it to perfection. Dive in now!
Meta Canonicalnull
Boilerpipe Text
Scripts have been helping people execute a lot of commands and perform complicated tasks like file operations. The next big step in scripting came in the form of automation, which made scripts even more helpful. Automation in Bash (Bourne Again SHell) command language scripts reduces human efforts and errors, improves efficiency, and maintains consistency. In this article, we will be learning about one important control flow statement: the Bash for loop. A “for loop” in Bash scripting is a control flow statement that allows code to be executed repeatedly based on a list of items or a sequence of numbers. The syntax involves iterating over each item in a list and executing specified commands. Using for loops in Unix based systems is crucial for automation. Some benefits of using a for loop in Bash are Simplify repetitive tasks Reduce human effort Save plenty of time by executing tasks quickly Cut down human errors via automation of processes. What is a Bash For Loop? In simple words, a Bash for loop is a control structure to repeatedly execute specified commands for all the items in a list. In a bash for loop, you have to specify a variable and a list or range to execute the commands on. Bash for loop template for “the item” in “the list”<br />do<br />“sample command 1”<br />“sample command 2”<br />…<br />done Why Should You Use Bash for Loops? Because it increases your efficiency and productivity exponentially. Multiple commands can be executed for each item in a list or sequence which drastically reduces the time and effort involved if the same has to be done manually. A lot of operations like system monitoring, data processing, and file processing can be done via bash for loops which adds one more reason why you should use bash for loops. Here are some relatable examples to get you started in increasing levels of complexity. If you have noticed the script starting with #!/bin/bash, it is called a shebang. Shebang tells the device that this is a bash script and has to be run using Bash shell. If you would like to print the file size of each file in a directory !/bin/bash<br />DIRECTORY="/sample_directory_path_here"<br />for file in "$DIRECTORY"/*<br />do<br />echo "File: $(basename "$file") - Size: $(stat -c%s "$file") bytes"<br />done The output will be: File: file1.jpg - Size: 150 bytes<br />File: file2.png - Size: 300 bytes If you would like to iterate over multiple directories and compress each file !/bin/bash<br />PARENT_DIR="/sample_directory_path_here"<br />for dir in "$PARENT_DIR"/*<br />do<br />if [ -d "$dir" ]; then<br />echo "Processing directory: $(basename "$dir")"<br />for file in "$dir"/*<br />do<br />if [ -f "$file" ]; then<br />gzip "$file"<br />echo "Compressed: $(basename "$file")"<br />fi<br />done<br />fi<br />done The output will be: Processing directory: directory1<br />Compressed: image1.jpg<br />Compressed: password.txt<br />Processing directory: directory2<br />Compressed: image2.jpg<br />Compressed: textfile.txt Off-by-one Error in Bash for Loop This is a common mistake while using Bash for loops. The off-by-one error occurs when the loop iterates either one time more or one time less. To understand this better, if you would want to iterate a sequence from 1 to 10, you should use {1..5} and not {1..6}. Recap and Other Ways to Polish Bash for Loops Congratulations! You are now ready to continue your path in writing perfect for loops in Bash. Time to automate some mundane daily tasks. If you would like to be a bash for loops master, practice your scripting skills with nested loops. Some references to help you further Cheat sheet for Bash commands (external link to RedHat’s official site) Bash Scripting 101 – As simplified as possible Bash script arguments tutorial Bash While Loop Examples
Markdown
- [Home](https://www.unixmen.com/) - [Linux distributions](https://www.unixmen.com/category/linux-distributions/) - [Linux tutorials](https://www.unixmen.com/category/linux-tutorials/) - [News](https://www.unixmen.com/category/news/) - [Frequently Asked Questions](https://www.unixmen.com/category/frequently-asked-questions/) - [Opensource](https://www.unixmen.com/category/opensource/) - [Unix](https://www.unixmen.com/category/unix/) - [Linux HowTo’s](https://www.unixmen.com/category/linux-howtos/) - [Linux Distro’s](https://www.unixmen.com/category/linux-distros/) - [Linux & Open Source News](https://www.unixmen.com/category/linux-open-source-news/) - [Contact Us](https://www.unixmen.com/contact-us/) Tuesday, March 3, 2026 - [About Us](https://www.unixmen.com/about-us/) - [Advertising on Unixmen](https://www.unixmen.com/advertising/) - [Become a Contributor](https://www.unixmen.com/work-for-us/) - [Unixmen collaborated with Unixstickers](https://www.unixmen.com/unixmen-collaborated-with-unixstickers/) - [Contact Us](https://www.unixmen.com/contact-us/) [![Unixmen](https://www.unixmen.com/wp-content/uploads/2016/02/unixmen-logo.png) Unixmen](https://www.unixmen.com/) [![Unixmen](https://www.unixmen.com/wp-content/uploads/2016/02/unixmen-logo-mobile.png)](https://www.unixmen.com/) [![Unixmen](https://www.unixmen.com/wp-content/uploads/2016/02/unixmen-logo.png)](https://www.unixmen.com/) - [Home](https://www.unixmen.com/) - [Linux distributions](https://www.unixmen.com/category/linux-distributions/) - [Linux tutorials](https://www.unixmen.com/category/linux-tutorials/) - [News](https://www.unixmen.com/category/news/) - [Frequently Asked Questions](https://www.unixmen.com/category/frequently-asked-questions/) - [Opensource](https://www.unixmen.com/category/opensource/) - [Unix](https://www.unixmen.com/category/unix/) - [Linux HowTo’s](https://www.unixmen.com/category/linux-howtos/) - [Linux Distro’s](https://www.unixmen.com/category/linux-distros/) - [Linux & Open Source News](https://www.unixmen.com/category/linux-open-source-news/) - [Contact Us](https://www.unixmen.com/contact-us/) [Home](https://www.unixmen.com/) [Featured](https://www.unixmen.com/category/featured-2/ "View all posts in Featured") [Shell Scripting](https://www.unixmen.com/category/featured-2/shell-scripting/ "View all posts in Shell Scripting") Bash For Loop: A Complete Guide for Perfect Scripts # Bash For Loop: A Complete Guide for Perfect Scripts By [Edwin](https://www.unixmen.com/author/0971762527/) [Share on Facebook](https://www.facebook.com/sharer.php?u=https%3A%2F%2Fwww.unixmen.com%2Fbash-for-loop-a-complete-guide-for-perfect-scripts%2F) [Tweet on Twitter](https://twitter.com/intent/tweet?text=Bash+For+Loop%3A+A+Complete+Guide+for+Perfect+Scripts&url=https%3A%2F%2Fwww.unixmen.com%2Fbash-for-loop-a-complete-guide-for-perfect-scripts%2F&via=unixmen) - [tweet](https://twitter.com/share) [![bash for loop](https://www.unixmen.com/wp-content/uploads/2024/05/bash-for-loop-696x209.png)![bash for loop](https://www.unixmen.com/wp-content/uploads/2024/05/bash-for-loop-696x209.png)](https://www.unixmen.com/wp-content/uploads/2024/05/bash-for-loop.png) ![bash for loop](https://www.unixmen.com/wp-content/uploads/2024/05/bash-for-loop.png) ![bash for loop](https://www.unixmen.com/wp-content/uploads/2024/05/bash-for-loop.png) Scripts have been helping people execute a lot of commands and perform complicated tasks like file operations. The next big step in scripting came in the form of automation, which made scripts even more helpful. Automation in Bash (Bourne Again SHell) command language scripts reduces human efforts and errors, improves efficiency, and maintains consistency. In this article, we will be learning about one important control flow statement: the Bash for loop. A “for loop” in Bash scripting is a control flow statement that allows code to be executed repeatedly based on a list of items or a sequence of numbers. The syntax involves iterating over each item in a list and executing specified commands. Using for loops in Unix based systems is crucial for automation. Some benefits of using a for loop in Bash are - Simplify repetitive tasks - Reduce human effort - Save plenty of time by executing tasks quickly - Cut down human errors via automation of processes. ## What is a Bash For Loop? In simple words, a Bash for loop is a control structure to repeatedly execute specified commands for all the items in a list. In a bash for loop, you have to specify a variable and a list or range to execute the commands on. **Bash for loop template** for “the item” in “the list”\<br /\>do\<br /\>“sample command 1”\<br /\>“sample command 2”\<br /\>…\<br /\>done ## Why Should You Use Bash for Loops? Because it increases your efficiency and productivity exponentially. Multiple commands can be executed for each item in a list or sequence which drastically reduces the time and effort involved if the same has to be done manually. A lot of operations like system monitoring, data processing, and file processing can be done via bash for loops which adds one more reason why you should use bash for loops. Here are some relatable examples to get you started in increasing levels of complexity. If you have noticed the script starting with \#!/bin/bash, it is called a shebang. Shebang tells the device that this is a bash script and has to be run using Bash shell. ### If you would like to print the file size of each file in a directory !/bin/bash\<br /\>DIRECTORY="/sample\_directory\_path\_here"\<br /\>for file in "\$DIRECTORY"/\*\<br /\>do\<br /\>echo "File: \$(basename "\$file") - Size: \$(stat -c%s "\$file") bytes"\<br /\>done The output will be: File: file1.jpg - Size: 150 bytes\<br /\>File: file2.png - Size: 300 bytes ### If you would like to iterate over multiple directories and compress each file !/bin/bash\<br /\>PARENT\_DIR="/sample\_directory\_path\_here"\<br /\>for dir in "\$PARENT\_DIR"/\*\<br /\>do\<br /\>if \[ -d "\$dir" \]; then\<br /\>echo "Processing directory: \$(basename "\$dir")"\<br /\>for file in "\$dir"/\*\<br /\>do\<br /\>if \[ -f "\$file" \]; then\<br /\>gzip "\$file"\<br /\>echo "Compressed: \$(basename "\$file")"\<br /\>fi\<br /\>done\<br /\>fi\<br /\>done The output will be: Processing directory: directory1\<br /\>Compressed: image1.jpg\<br /\>Compressed: password.txt\<br /\>Processing directory: directory2\<br /\>Compressed: image2.jpg\<br /\>Compressed: textfile.txt ## Off-by-one Error in Bash for Loop This is a common mistake while using Bash for loops. The off-by-one error occurs when the loop iterates either one time more or one time less. To understand this better, if you would want to iterate a sequence from 1 to 10, you should use {1..5} and not {1..6}. ### Recap and Other Ways to Polish Bash for Loops Congratulations! You are now ready to continue your path in writing perfect for loops in Bash. Time to automate some mundane daily tasks. If you would like to be a bash for loops master, practice your scripting skills with nested loops. ### Some references to help you further - [Cheat sheet for Bash commands](https://developers.redhat.com/cheat-sheets/bash-shell-cheat-sheet) (external link to RedHat’s official site) - [Bash Scripting 101 – As simplified as possible](https://www.unixmen.com/bash-scripting-basics/) - [Bash script arguments tutorial](https://www.unixmen.com/bash-script-arguments-a-comprehensive-guide/) - [Bash While Loop Examples](https://www.unixmen.com/bash-while-loop-examples-for-loops-until-loops-and-more/) [Edwin](https://www.unixmen.com/author/0971762527/) #### Latest Articles [![install MySQL](https://www.unixmen.com/wp-content/uploads/2017/05/MySQL-150x150.png)![install MySQL](https://www.unixmen.com/wp-content/uploads/2017/05/MySQL-150x150.png)](https://www.unixmen.com/how-to-repair-mysql-database-in-linux/ "How to Repair MySQL Database in Linux?") ### [How to Repair MySQL Database in Linux?](https://www.unixmen.com/how-to-repair-mysql-database-in-linux/ "How to Repair MySQL Database in Linux?") [Linux HowTo's](https://www.unixmen.com/category/linux-howtos/) [Janus Atienza](https://www.unixmen.com/author/landocsgp/) \- February 18, 2026 [0](https://www.unixmen.com/how-to-repair-mysql-database-in-linux/#respond) MySQL database files are prone to corruption and inconsistencies. They can easily get corrupted due to several reasons, such as virus attack on the... [![SSH to your Linux systems from Android](https://www.unixmen.com/wp-content/uploads/2024/11/image-66-150x150.png)![SSH to your Linux systems from Android](https://www.unixmen.com/wp-content/uploads/2024/11/image-66-150x150.png)](https://www.unixmen.com/uses-of-linux-how-individuals-and-organizations-use-it/ "Uses of Linux: How Individuals and Organizations Use It") ### [Uses of Linux: How Individuals and Organizations Use It](https://www.unixmen.com/uses-of-linux-how-individuals-and-organizations-use-it/ "Uses of Linux: How Individuals and Organizations Use It") [Linux HowTo's](https://www.unixmen.com/category/linux-howtos/) [Janus Atienza](https://www.unixmen.com/author/landocsgp/) \- February 10, 2026 [0](https://www.unixmen.com/uses-of-linux-how-individuals-and-organizations-use-it/#respond) Ever ask yourself why so many people talk about Linux and why it keeps showing up in phones, offices, and even at home? Linux... [![](https://www.unixmen.com/wp-content/uploads/2025/06/Practical-Applications-150x150.jpg)![](https://www.unixmen.com/wp-content/uploads/2025/06/Practical-Applications-150x150.jpg)](https://www.unixmen.com/debian-hosting-is-not-trendy-and-thats-why-it-wins/ "Debian Hosting Is Not Trendy, and That’s Why It Wins") ### [Debian Hosting Is Not Trendy, and That’s Why It Wins](https://www.unixmen.com/debian-hosting-is-not-trendy-and-thats-why-it-wins/ "Debian Hosting Is Not Trendy, and That’s Why It Wins") [Hosting](https://www.unixmen.com/category/hosting/) [Janus Atienza](https://www.unixmen.com/author/landocsgp/) \- February 4, 2026 [0](https://www.unixmen.com/debian-hosting-is-not-trendy-and-thats-why-it-wins/#respond) Hosting based on Debian OS is far from modernized control panels, AI-integration, and all other things new Linux distros are trying to hook you... [![Unixmen Logo](https://www.unixmen.com/wp-content/uploads/2016/02/unixmen-logo-footer.png)![Unixmen Logo](https://www.unixmen.com/wp-content/uploads/2016/02/unixmen-logo-footer.png)](https://www.unixmen.com/) ABOUT US Unixmen provide Linux Howtos, Tutorials, Tips & Tricks ,Opensource News. It cover most popular distros like Ubuntu, LinuxMint, Fedora, Centos. It is your Gate to the the world of Linux/Unix and Opensource in General. [Privacy Policy](https://ads.landocsventures.com/unixmen/Privacy/Privacy.pdf) [Cookie Policy](https://ads.landocsventures.com/unixmen/Privacy/COOKIE.pdf) [Advertise](https://www.unixmen.com/advertising/) © Copyright 2020 - Newspaper 6 by TagDiv
Readable Markdown
[![bash for loop](https://www.unixmen.com/wp-content/uploads/2024/05/bash-for-loop-696x209.png)](https://www.unixmen.com/wp-content/uploads/2024/05/bash-for-loop.png) ![bash for loop](https://www.unixmen.com/wp-content/uploads/2024/05/bash-for-loop.png) Scripts have been helping people execute a lot of commands and perform complicated tasks like file operations. The next big step in scripting came in the form of automation, which made scripts even more helpful. Automation in Bash (Bourne Again SHell) command language scripts reduces human efforts and errors, improves efficiency, and maintains consistency. In this article, we will be learning about one important control flow statement: the Bash for loop. A “for loop” in Bash scripting is a control flow statement that allows code to be executed repeatedly based on a list of items or a sequence of numbers. The syntax involves iterating over each item in a list and executing specified commands. Using for loops in Unix based systems is crucial for automation. Some benefits of using a for loop in Bash are - Simplify repetitive tasks - Reduce human effort - Save plenty of time by executing tasks quickly - Cut down human errors via automation of processes. ## What is a Bash For Loop? In simple words, a Bash for loop is a control structure to repeatedly execute specified commands for all the items in a list. In a bash for loop, you have to specify a variable and a list or range to execute the commands on. **Bash for loop template** for “the item” in “the list”\<br /\>do\<br /\>“sample command 1”\<br /\>“sample command 2”\<br /\>…\<br /\>done ## Why Should You Use Bash for Loops? Because it increases your efficiency and productivity exponentially. Multiple commands can be executed for each item in a list or sequence which drastically reduces the time and effort involved if the same has to be done manually. A lot of operations like system monitoring, data processing, and file processing can be done via bash for loops which adds one more reason why you should use bash for loops. Here are some relatable examples to get you started in increasing levels of complexity. If you have noticed the script starting with \#!/bin/bash, it is called a shebang. Shebang tells the device that this is a bash script and has to be run using Bash shell. ### If you would like to print the file size of each file in a directory !/bin/bash\<br /\>DIRECTORY="/sample\_directory\_path\_here"\<br /\>for file in "\$DIRECTORY"/\*\<br /\>do\<br /\>echo "File: \$(basename "\$file") - Size: \$(stat -c%s "\$file") bytes"\<br /\>done The output will be: File: file1.jpg - Size: 150 bytes\<br /\>File: file2.png - Size: 300 bytes ### If you would like to iterate over multiple directories and compress each file !/bin/bash\<br /\>PARENT\_DIR="/sample\_directory\_path\_here"\<br /\>for dir in "\$PARENT\_DIR"/\*\<br /\>do\<br /\>if \[ -d "\$dir" \]; then\<br /\>echo "Processing directory: \$(basename "\$dir")"\<br /\>for file in "\$dir"/\*\<br /\>do\<br /\>if \[ -f "\$file" \]; then\<br /\>gzip "\$file"\<br /\>echo "Compressed: \$(basename "\$file")"\<br /\>fi\<br /\>done\<br /\>fi\<br /\>done The output will be: Processing directory: directory1\<br /\>Compressed: image1.jpg\<br /\>Compressed: password.txt\<br /\>Processing directory: directory2\<br /\>Compressed: image2.jpg\<br /\>Compressed: textfile.txt ## Off-by-one Error in Bash for Loop This is a common mistake while using Bash for loops. The off-by-one error occurs when the loop iterates either one time more or one time less. To understand this better, if you would want to iterate a sequence from 1 to 10, you should use {1..5} and not {1..6}. ### Recap and Other Ways to Polish Bash for Loops Congratulations! You are now ready to continue your path in writing perfect for loops in Bash. Time to automate some mundane daily tasks. If you would like to be a bash for loops master, practice your scripting skills with nested loops. ### Some references to help you further - [Cheat sheet for Bash commands](https://developers.redhat.com/cheat-sheets/bash-shell-cheat-sheet) (external link to RedHat’s official site) - [Bash Scripting 101 – As simplified as possible](https://www.unixmen.com/bash-scripting-basics/) - [Bash script arguments tutorial](https://www.unixmen.com/bash-script-arguments-a-comprehensive-guide/) - [Bash While Loop Examples](https://www.unixmen.com/bash-while-loop-examples-for-loops-until-loops-and-more/)
Shard67 (laksa)
Root Hash12996476488780439067
Unparsed URLcom,unixmen!www,/bash-for-loop-a-complete-guide-for-perfect-scripts/ s443