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它一直告诉我,他们的and语句是错误的fi

答案1

if/关键字elif后面需要一些空格(否则 shell 将无法理解它们与后面的单词是分开的):

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

相关内容