Bashのfor文の書き方: ループ文で繰り返し処理を行う - なるぽのブログ より。
for i in 1 2 3;do;echo -n $i;done
for ((i=1 i<=3; i++)); do;
echo -n $i
done
for ((i=1; i<=3; i++)); do; echo -n $i; done
arr=(1 2 3);for i in ${arr[@]};do; echo -n $i; done
arr=(1 2 3);for i in $arr;do;echo -n $i;done
arr=(1 2 3)
for i in $arr;do
echo -n $i
done
123
arr=("The cat" "The dog")
for el in ${arr[@]}; do
echo $el
done
# The
# cat
# The
# dog
arr=("The cat" "The dog")
for el in "${arr[@]}"; do
echo $el
done
# The cat
# The dog
for ((i=0; i<4; i++)); do
if [ $i == 2 ]; then
break
# OR continue
fi
done
echo $i
# 2
# OR 4
Example
arr=(foo bar doo); for n in $arr; do; cargo new project_${n} --bin; done
Created binary (application) `project_foo` package Created binary (application) `project_bar` package Created binary (application) `project_doo` package