thenとfiの構文エラー

thenとfiの構文エラー

私は次のスクリプトを書いた。

#!/bin/bash
#Greetings
#This program displays greetings according to the time of the day
#
echo
hour='date +%H'
if[ "$hour" -le 12 ]
then
    echo "GOOD MORNING"
elif[ "$hour" -le 18 ]
then
    echo "GOOD AFTERNOON"
else
    echo "GOOD EVENING"
fi
done 
echo

thenそれでも彼らの声明が間違っていると言っていますfi

ベストアンサー1

if/keywordsの後にはいくつかのスペースが必要ですelif(そうしないと、シェルはそのスペースが次の単語から分離されていることを認識しません)。

if [ "$hour" -le 12 ]; then echo "hour is less than or equal to twelve"; fi

おすすめ記事