Tuesday, April 29, 2008

Bash 'for' loop examples

I can never remember the syntax for bash for loops:

#!/bin/bash
for i in $( ls ); do
echo item: $i
done

#!/bin/bash
for i in `seq 1 10`; do
echo $i
done

#!/bin/bash
for ((i=100;i<=115;i+=1)); do
echo $i
sleep 1
echo $i > /dev/ttyS1
done

No comments: