bash スクリプトで予期しない単語 (「then」を期待)

bash スクリプトで予期しない単語 (「then」を期待)

こんにちは、これは私のスクリプトです。

#!/bin/bash
service=dmsspeechbatch-0.0.jar #(name of the service)
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo "$service is running"
else
cd /application/TextToSpeech/dmsspeechbatch
nohup java -jar target/dmsspeechbatch-0.0.jar &
fi

このエラーが発生しています

構文エラー: 予期しない単語です ("then" が必要です)

どうすればいいですか?

ありがとう!

答え1

bashこの行では:

if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))

すべきである

if [ $(ps -ef | grep -v grep | grep $service | wc -l) -gt 0 ]

また、この行は次のように最適化できます。

if [ $(pgrep $service | wc -l) -gt 0 ]

最初の行の先頭のスペースも削除します

関連情報