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 ]

또한 첫 번째 줄의 선행 공백을 제거합니다.

관련 정보