コマンドをn回繰り返して終了するには?

コマンドをn回繰り返して終了するには?

インストールを自動化したい場合は、gksuを使用してダウンロードしたインストーラを実行する必要があります。私は試した:

試行= 0
  ~まで
  gksuコマンド;
    試行=$((試行+1))
    if["$try"-gt 3];
      1番出口
    フィリピン諸島
  完璧

しかし、3回目の試みまでは終了しません。 gksuが終了コード0または0以外の終了コードで終了するかどうかは問題ではありません。私が望むもの:私はこれをどうやって行うことができますか?
while gksu command's exit code is not 0 and attempt number is not 3 repeat gksu command. If exit code is not 0 but attempt number is 3, exit the whole script. If exit code is 0 leave cycle and continue processing the script.

ベストアンサー1

時間があれば、seq次のようにすることができます。

for attempt in $(seq 1 3)
do
  gksu command && break
done

seq利用できませんが、bashがあり、使用したい場合:

for((attempt=1;attempt<=3;attempt++))
do 
  gksu command && break
done

より簡単に(ドルベン):

for attempt in {1..3} 
do
  gksu command && break
done

おすすめ記事