Bash

意外標記“elif”

  • September 8, 2019

我在這裡嘗試編寫可在特定日期工作的 shell,Sun Solaris 10 不支持新功能,但我不斷得到syntax error near unexpected tokenelif'`

DAY_Word=$(date +%A)

Nomral_Day=$(date +%d)
MONTH=$(date +%m)

if [ "$Nomral_Day" -eq 01 ] || [ "$Nomral_Day" -eq 16 ] && [ "$MONTH" -ne 02 ]
then

###run integrity after

elif [ "$Nomral_Day" -eq 12 ] || [ "$Nomral_Day" -eq 28 ] && [ "$DAY_Word" = "Thursday" ] && [ "$MONTH" -ne 02 ]
then

### run integrity before

elif [ "$Nomral_Day" -eq 13 ] || [ "$Nomral_Day" -eq 29 ] && [ "$DAY_Word" != "Friday" ] && [ "$MONTH" -ne 02 ]
then

### run integrity before

elif [ "$Nomral_Day" -eq 25 ] && [ "$DAY_Word" = "Thursday" ] && [ "$MONTH" -eq 02 ]
then

## run integrity before

elif [ "$Nomral_Day" -eq 26 ] && [ "$DAY_Word" != "Friday" ] && [ "$MONTH" -eq 02 ]
then

## run integrity before

fi

不能省略 and 之間的then命令elif。您必須包含一個命令。

添加命令true,您的腳本應該可以工作。

引用自:https://unix.stackexchange.com/questions/539683