2010年8月13日星期五

BASH For Loop Sequence

Here are a few different ways to do a loop over a range of numbers:
for I in {1..10}; do echo $I; done

for I in 1 2 3 4 5 6 7 8 9 10; do echo $I; done

for I in $(seq 1 10); do echo $I; done

for ((I=1; I <= 10 ; I++)); do echo $I; done

numbered hostnames padded with zeros:
for ((I=1; I <= 29 ; I++)); do
echo `printf "node%02d\n" $I`;
done

http://www.cyberciti.biz/faq/bash-for-loop/

没有评论:

发表评论