whileループで予期しない「完了」マーク

whileループで予期しない「完了」マーク

このbashスクリプトの構文エラーが何であるかを知りたいです。

#!/bin/bash
CURRENT=1594184400
while true do
  NEXT=$((CURRENT+300))
  CURRENT=$NEXT
done

私が得たもの

syntax error near unexpected token `done'

間違い?

ベストアンサー1

true2行目の後にセミコロンを追加するか、do次の行を別々に追加する必要があります。

次のいずれか:

#!/bin/bash
CURRENT=1594184400
while true; do     
  NEXT=$((CURRENT+300))
  CURRENT=$NEXT
done

またはこれ:

#!/bin/bash
CURRENT=1594184400
while true 
do
  NEXT=$((CURRENT+300))
  CURRENT=$NEXT
done

ここでシェルスクリプトのエラーを確認できます。

https://www.shellcheck.net/

bash -n script端末で実行してエラーを確認することもできます。

おすすめ記事