Programming Code Examples

How To Use bash For Loop In One Line1 min read

In bash, you can use a for loop in a single line by using the following syntax:

Here’s an example that prints out the numbers from 1 to 5:

This will output the following:

You can also use the seq command to generate a range of numbers, like this:

This will have the same effect as the previous example.

Note that the ; characters are used to separate the different commands, and the do and done keywords mark the beginning and end of the loop, respectively.

Add comment