KandZ – Tuts

We like to help…!

Linux CLI 64 ๐Ÿง for loop in shell scripts

a - for loop in shell scripts intro
for loop is used to iterate over a sequence of items or values
This type of loop is very useful for executing the same command or set of commands multiple times with different inputs.
syntax:

for variable in item1 item2 ... itemN
do
Commands to be executed for each iteration
done

varialbe is a placeholder that takes on each value from the item list, one at a time.
items are values or items (like numbers, strings, file names) that the loop will iterate over.
you can also use C-style syntax:

for (( initialization; condition; increment ))
do
Commands to be executed for each iteration
done

Initialization โ†’ This expression is executed only once before the loop starts. It usually initializes one or more variables.
Condition โ†’ This expression is evaluated at the start of every iteration. If it evaluates to true (non-zero), the loop body executes; if false (zero), the loop ends.
Increment โ†’ This expression is executed after each iteration of the loop body, typically used to update the loop variable(s).

b - for loop examples
Simple loop
Simple loop using seq command
Simple loop using C-style syntax
Simple loop using {start..end} syntax
Loop through all .sh files in the current directory
Nested loops
Loop through each line of the output from 'ls' command

Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!

Leave a Reply