âčïž Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.2 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://pendrivelinux.com/for-linux-command/ |
| Last Crawled | 2026-04-01 05:05:56 (6 days ago) |
| First Indexed | 2023-10-27 20:04:00 (2 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Creating a For Loop Bash Script in Linux â· Looping Command |
| Meta Description | For Loop Bash. For is a loop command in Linux; A bash command used in Linux and other Unix like operating systems to loop through a series of commands. It is |
| Meta Canonical | null |
| Boilerpipe Text | For Loop Bash. For is a loop command in Linux; A bash command used in Linux and other Unix like operating systems to loop through a series of commands. It is most commonly used in shell scripts or bash to help automate tasks or routines.
â°
Table of Contents
How to Create a For Loop Bash Script in Linux
A Fruity Looking For Loop Bash Script
For Loop Bash Script to iterate through a list of filenames
For Loop Bash Script to iterate through a list of numbers
How to Create a For Loop Bash Script in Linux
To make a For Loop Bash Script, in Linux or Unix, the basic syntax is as follows:
#!/bin/bash
for variable in list
do
commands
done
Here is how the for loop bash script above, works.
The script starts with the shebang line
#!/bin/bash
, which tells the system to use the bash shell to interpret the script.
The
for
Linux command starts by defining a
variable
 to hold the current item in list.
The
list
 can be used to represent any list of items, such as filenames, directories, or strings. The for command will loop through each item in the list and assign it to the variable.
For each item in the list, the
commands
defined between the
do
and
done
 block will be executed.
Once all items in the list have been processed, the loop is stopped with
done
, clearing the variable for use elsewhere, and the for command is complete
A Fruity Looking For Loop Bash Script
In the following example, the
for
command is used in a bash script to iterate over a list of three common fruits (
apple
,
banana
, and
orange
) and assigning each one to the
fruit
variable. For each fruit in the list, the
echo command
is used to print a message to the screen that includes the fruit name.
#!/bin/bash
for fruit in apple banana orange
do
echo "I like to eat $fruit"
done
When you run this script, you'll see output that looks like this. Notice how a new line is printed for each fruit.
I like to eat apple
I like to eat banana
I like to eat orange
Note
: you can also use * wildcards to automatically populate a list of items to iterate through, as you'll see in this next example.
For Loop Bash Script to iterate through a list of filenames
#!/bin/bash
for file in *.txt
do
echo "Processing file: $file"
# add your commands to process for each file here
done
In the example above, the
for
command is used to loop through all files within the current directory that have a
.txt
extension. The
echo
 command is simply being used to print the name of each file to the screen.
You can add your own commands to process each file as needed by replacing everything following the # commented line in the code.
For Loop Bash Script to iterate through a list of numbers
You can also use the for loop command in a Linux bash script to iterate through a list of numbers as shown below.
#!/bin/bash
for i in {1..10}
do
echo "Number: $i"
# add your commands to process for each number here
done
How bash script for loop numerical iteration works:
In the previous example, the '
for
'
command is used to loop through numbers 1 through 10. The '
echo
' command is also being used to print each number to the screen. Again, you can replace the commented line with your own commands to process with each line number as needed.
As you can see, the for command can be a powerful tool to use for automating tasks through shell scripts while running from Linux operating systems. With a little practice, you'll be using it to create cool scripts up front that save you a lot of time and effort in the long run.
If you found this post useful, you might also be interested in learning how to chain commands using
And Linux Command
. |
| Markdown | [Skip to content](https://pendrivelinux.com/for-linux-command/#content)
[](https://pendrivelinux.com/)
[Home](https://pendrivelinux.com/) » [Get Started Using Linux](https://pendrivelinux.com/category/using-linux/)
# Creating a For Loop Bash Script in Linux
For Loop Bash. For is a loop command in Linux; A bash command used in Linux and other Unix like operating systems to loop through a series of commands. It is most commonly used in shell scripts or bash to help automate tasks or routines.
â°
Table of Contents
- [How to Create a For Loop Bash Script in Linux](https://pendrivelinux.com/for-linux-command/#how-to-create-a-for-loop-bash-script-in-linux)
- [A Fruity Looking For Loop Bash Script](https://pendrivelinux.com/for-linux-command/#a-fruity-looking-for-loop-bash-script)
- [For Loop Bash Script to iterate through a list of filenames](https://pendrivelinux.com/for-linux-command/#for-loop-bash-script-to-iterate-through-a-list-of-filenames)
- [For Loop Bash Script to iterate through a list of numbers](https://pendrivelinux.com/for-linux-command/#for-loop-bash-script-to-iterate-through-a-list-of-numbers)
## How to Create a For Loop Bash Script in Linux
To make a For Loop Bash Script, in Linux or Unix, the basic syntax is as follows:
```
#!/bin/bash
for variable in list
do
commands
done
```
Here is how the for loop bash script above, works.
1. The script starts with the shebang line **\#!/bin/bash**, which tells the system to use the bash shell to interpret the script.
2. The **for** Linux command starts by defining a **variable** to hold the current item in list.
3. The **list** can be used to represent any list of items, such as filenames, directories, or strings. The for command will loop through each item in the list and assign it to the variable.
4. For each item in the list, the **commands** defined between the **do** and **done** block will be executed.
5. Once all items in the list have been processed, the loop is stopped with **done**, clearing the variable for use elsewhere, and the for command is complete
### A Fruity Looking For Loop Bash Script
In the following example, the **for** command is used in a bash script to iterate over a list of three common fruits (**apple**, **banana**, and **orange**) and assigning each one to the **fruit** variable. For each fruit in the list, the **echo command** is used to print a message to the screen that includes the fruit name.
```
#!/bin/bash
for fruit in apple banana orange
do
echo "I like to eat $fruit"
done
```
When you run this script, you'll see output that looks like this. Notice how a new line is printed for each fruit.
```
I like to eat apple
I like to eat banana
I like to eat orange
```
**Note**: you can also use \* wildcards to automatically populate a list of items to iterate through, as you'll see in this next example.
### For Loop Bash Script to iterate through a list of filenames
```
#!/bin/bash
for file in *.txt
do
echo "Processing file: $file"
# add your commands to process for each file here
done
```
In the example above, the **for** command is used to loop through all files within the current directory that have a **.txt** extension. The **echo** command is simply being used to print the name of each file to the screen. You can add your own commands to process each file as needed by replacing everything following the \# commented line in the code.
### For Loop Bash Script to iterate through a list of numbers
You can also use the for loop command in a Linux bash script to iterate through a list of numbers as shown below.
```
#!/bin/bash
for i in {1..10}
do
echo "Number: $i"
# add your commands to process for each number here
done
```
How bash script for loop numerical iteration works:
In the previous example, the '**for**' command is used to loop through numbers 1 through 10. The '**echo**' command is also being used to print each number to the screen. Again, you can replace the commented line with your own commands to process with each line number as needed.
As you can see, the for command can be a powerful tool to use for automating tasks through shell scripts while running from Linux operating systems. With a little practice, you'll be using it to create cool scripts up front that save you a lot of time and effort in the long run.
If you found this post useful, you might also be interested in learning how to chain commands using [And Linux Command](https://pendrivelinux.com/and-linux-command/).
***
By [Pendrive Linux](https://pendrivelinux.com/about/ "About Pen Drive Linux") \| 4 min read
Similar for loop bash
- [Using and Linux Command to Chain Commands](https://pendrivelinux.com/and-linux-command/)
Pendrive Linux Categories
- [Best Bootable USB Creator Software](https://pendrivelinux.com/category/bootable-usb-creator/)
- [Create Bootable USB Drives](https://pendrivelinux.com/category/create-bootable-usb-drives/)
- [Get Started Using Linux](https://pendrivelinux.com/category/using-linux/)
- [Linux Boot Commands](https://pendrivelinux.com/category/cheatcodes/)
- [Virtual Machine Emulation](https://pendrivelinux.com/category/virtual-machine/)
Pendrive Help & Tips
- [How to Reset USB Drives](https://pendrivelinux.com/restoring-your-usb-key-partition/ "Learn how to reset USB drives to factory settings")
- [Recover Lost USB Drive Space](https://pendrivelinux.com/recover-lost-space-on-a-usb-flash-drive/ "Guide to recover and reclaim lost space on your USB flash drive")
- [Fastest USB Flash Drives](https://pendrivelinux.com/fastest-usb-flash-drives/ "Discover the fastest USB flash drives")
- [Setup BIOS for USB Booting](https://pendrivelinux.com/category/bios-usb-boot-options/ "Learn how to configure BIOS settings for USB booting")
LinuxÂź is a registered trademark of Linus Torvalds. WindowsÂź is a trademark of Microsoft.
© 2006 - 2026 Pendrive Linux â Helping you effortlessly make Live bootable Linux USB boot sticks, since 2006.
[Privacy](https://pendrivelinux.com/privacy-policy/) \| [Contact](https://pendrivelinux.com/contact/)
[X](https://x.com/pendrivelinux) [Pin](https://www.pinterest.com/PendriveLinux/) [YT](https://www.youtube.com/@PendriveLinuxUSB) [Rd](https://www.reddit.com/user/pendrivelinux/) [IG](https://www.instagram.com/pendrivelinux) |
| Readable Markdown | For Loop Bash. For is a loop command in Linux; A bash command used in Linux and other Unix like operating systems to loop through a series of commands. It is most commonly used in shell scripts or bash to help automate tasks or routines.
â°
Table of Contents
- [How to Create a For Loop Bash Script in Linux](https://pendrivelinux.com/for-linux-command/#how-to-create-a-for-loop-bash-script-in-linux)
- [A Fruity Looking For Loop Bash Script](https://pendrivelinux.com/for-linux-command/#a-fruity-looking-for-loop-bash-script)
- [For Loop Bash Script to iterate through a list of filenames](https://pendrivelinux.com/for-linux-command/#for-loop-bash-script-to-iterate-through-a-list-of-filenames)
- [For Loop Bash Script to iterate through a list of numbers](https://pendrivelinux.com/for-linux-command/#for-loop-bash-script-to-iterate-through-a-list-of-numbers)
## How to Create a For Loop Bash Script in Linux
To make a For Loop Bash Script, in Linux or Unix, the basic syntax is as follows:
```
#!/bin/bash
for variable in list
do
commands
done
```
Here is how the for loop bash script above, works.
1. The script starts with the shebang line **\#!/bin/bash**, which tells the system to use the bash shell to interpret the script.
2. The **for** Linux command starts by defining a **variable** to hold the current item in list.
3. The **list** can be used to represent any list of items, such as filenames, directories, or strings. The for command will loop through each item in the list and assign it to the variable.
4. For each item in the list, the **commands** defined between the **do** and **done** block will be executed.
5. Once all items in the list have been processed, the loop is stopped with **done**, clearing the variable for use elsewhere, and the for command is complete
### A Fruity Looking For Loop Bash Script
In the following example, the **for** command is used in a bash script to iterate over a list of three common fruits (**apple**, **banana**, and **orange**) and assigning each one to the **fruit** variable. For each fruit in the list, the **echo command** is used to print a message to the screen that includes the fruit name.
```
#!/bin/bash
for fruit in apple banana orange
do
echo "I like to eat $fruit"
done
```
When you run this script, you'll see output that looks like this. Notice how a new line is printed for each fruit.
```
I like to eat apple
I like to eat banana
I like to eat orange
```
**Note**: you can also use \* wildcards to automatically populate a list of items to iterate through, as you'll see in this next example.
### For Loop Bash Script to iterate through a list of filenames
```
#!/bin/bash
for file in *.txt
do
echo "Processing file: $file"
# add your commands to process for each file here
done
```
In the example above, the **for** command is used to loop through all files within the current directory that have a **.txt** extension. The **echo** command is simply being used to print the name of each file to the screen. You can add your own commands to process each file as needed by replacing everything following the \# commented line in the code.
### For Loop Bash Script to iterate through a list of numbers
You can also use the for loop command in a Linux bash script to iterate through a list of numbers as shown below.
```
#!/bin/bash
for i in {1..10}
do
echo "Number: $i"
# add your commands to process for each number here
done
```
How bash script for loop numerical iteration works:
In the previous example, the '**for**' command is used to loop through numbers 1 through 10. The '**echo**' command is also being used to print each number to the screen. Again, you can replace the commented line with your own commands to process with each line number as needed.
As you can see, the for command can be a powerful tool to use for automating tasks through shell scripts while running from Linux operating systems. With a little practice, you'll be using it to create cool scripts up front that save you a lot of time and effort in the long run.
If you found this post useful, you might also be interested in learning how to chain commands using [And Linux Command](https://pendrivelinux.com/and-linux-command/).
*** |
| Shard | 164 (laksa) |
| Root Hash | 6596003835281742164 |
| Unparsed URL | com,pendrivelinux!/for-linux-command/ s443 |