Bashでループをn回繰り返す方法

Bashでループをn回繰り返す方法

次のシナリオがあります。

if [file exists]; then
   exit   
elif
   recheck if file exist (max 10 times)
   if found exit else recheck again as per counter  
fi 

ベストアンサー1

数が変数でない場合は、中かっこ拡張を使用できます。

for i in {1..10}   # you can also use {0..9}
do
  whatever
done

数が変数の場合は、次のseqコマンドを使用できます。

count=10
for i in $(seq $count)
do
  whatever
done

おすすめ記事