Skip to main content

Command Palette

Search for a command to run...

Learning Bash for Loop today

Updated
2 min readView as Markdown
D

Owner of howtouselinux.com. I work as a Linux engineer for over 20 years. Now I am a technical blogger and Software Engineer. I enjoy sharing learning and contributing to open-source.

Learning Bash for Loop today

#!/bin/bash

for i in $( ls ); do
  echo item: $i
done
#!/bin/bash
# Basic for loop
names='Stan Kyle Cartman'
for name in $names
do
echo $name
done
echo All done
#!/bin/bash
# Basic range in for loop
for value in {1..5}
do
echo $value
done
echo All done
#!/bin/bash
# Basic range with steps for loop
for value in {10..0..2}
do
echo $value
done
echo All done
#!/bin/bash
# Make a php copy of any html files
for value in $1/*.html
do
cp $value $1/$( basename -s .html $value ).php
done

Bash For Loop# Learning Bash for Loop today

#!/bin/bash

for i in $( ls ); do
  echo item: $i
done
#!/bin/bash
# Basic for loop
names='Stan Kyle Cartman'
for name in $names
do
echo $name
done
echo All done
#!/bin/bash
# Basic range in for loop
for value in {1..5}
do
echo $value
done
echo All done
#!/bin/bash
# Basic range with steps for loop
for value in {10..0..2}
do
echo $value
done
echo All done
#!/bin/bash
# Make a php copy of any html files
for value in $1/*.html
do
cp $value $1/$( basename -s .html $value ).php
done

Bash For Loop

What Is Bash in Linux?

10 Bash for Loop In One Line Examples

Linux Commands for Linux Beginners (Cheat Sheet)

More from this blog

Linux Skills

26 posts