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 ]

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

おすすめ記事