browser icon
You are using an insecure version of your web browser. Please update your browser!
Using an outdated browser makes your computer unsafe. For a safer, faster, more enjoyable user experience, please update your browser today or try a newer browser.

Bash For loop Example

Posted by on July 15, 2008

I’m always forgetting the syntax to make “for” loops in Bash. Anyhow, I know I will have to come back here to find it, so I thought I would write put up this quick example with the hope that it will be useful to others as well.

for i in $(seq 1 100); do echo -n “file${i} “; touch file${i} 2>&1; done

The the above for loop will create 100 files (called file1, file2, etc.).

another for loop exampe

for i in 1 2 3 4 cow
do
echo $i
done

# alternate:

for i in 1 2 3 4 cow; do echo $i;done

for i in `seq 1 10`

for ((j=1; j <= 10; j+=2))

while ((x++ < 10))

until ((x– < -10))

for i in $(ls)

for in in `cat /tmp/somefile`

Comments

comments

Leave a Reply

Your email address will not be published. Required fields are marked *

:)) :) :D (LOL) :-P (woot) ;-) :-o X-( ;-( :-& (angry) (annoyed) (bye) B-) (cozy) (sick) (: (goodluck) (griltongue) (mmm) (hungry) (music) (tears) (tongue) (unsure) (highfive) (dance) (doh) (brokenheart) (drinking) (girlkiss) (rofl) (money) (rock) (nottalking) (party) (sleeping) (thinking) (bringit) (worship) (applause) 8-) (gym) (heart) (devil) (lmao) (banana_cool) (banana_rock) (evil_grin) (headspin) (heart_beat) (ninja) (haha) (evilsmirk) (bigeyes) (funkydance) (idiot) (lonely) (scenic) (hassle) (panic) (okok) (yahoo) (blush) (fish_hit) (muhaha) (muscle) (taser) (beer) (coffee) (banana_ninja) (goal) (fireworks) (smileydance) (dance_bzz) (rusian)