另一个意外的标记“fi”错误
another unexpected token `fi' error
我正在尝试针对特定条件测试 7 天,并且需要考虑闰年。我认为我的逻辑是正确的,已经重复了 100 次。但出于某种原因,我不断收到同样的错误。
:~$ bin/shabbat/test
bin/shabbat/test: line 90: syntax error near unexpected token `fi'
bin/shabbat/test: line 90: ` fi'
请不要笑得太厉害。我不是程序员。我必须 copy/paste 有效的代码并更改它尝试让它做我想做的事。
#!/bin/bash
STORDIR="${HOME}/bin/shabbat/data"
DAY=28
MONTH=1
YEAR=2016
# Calculate next day accounting for leap years
function Next_Day
{
case ${ $MONTH } in
1)
FULL="31"
;;
2)
FULL="28"
;;
3)
FULL="31"
;;
4)
FULL="30"
;;
5)
FULL="31"
;;
6)
FULL="30"
;;
7)
FULL="31"
;;
8)
FULL="31"
;;
9)
FULL="30"
;;
10)
FULL="31"
;;
11)
FULL="30"
;;
12)
FULL="31"
;;
esac
if [[ "$DAY" -le "27" ]]; then
(( DAY++ ))
exit
elif [[ ${MONTH} == "2" ]]; then
rem1=$((YEAR%4))
rem2=$((YEAR%100))
rem3=$((YEAR%400))
if [ ${rem3} = "0" ]; then
$FULL="29"
exit
fi
if [ ${rem2} = "0" -a ${rem3} != "0" ]; then
# echo "$YEAR Is Not A Leap Year"
exit
fi
if [ ${rem1} = "0" -a ${rem2} != "0" ]; then
# echo "$YEAR Is A Leap Year"
$FULL="29"
else
# echo "$YEAR Is Not A Leap Year"
exit
fi
if [ ${DAY} = ${FULL} -a ${MONTH} -lt "12" ]; then
(( MONTH++ ))
(( DAY++ ))
exit
fi
elif [ ${DAY} = ${FULL} -a ${MONTH} = "12" ]; then
(( YEAR++ ))
let MONTH=1
let DAY=1
exit
fi
exit
fi
}
#################
# # Main Code # #
#################
for (( i = 1; i < 7; i++)); do
YOMTOVE=$(hdate -dhq $DAY $MONTH $YEAR | awk 'NR==3')
echo "$YOMTOVE"
if [[ -n "$YOMTOVE" ]]; then
grep ^"$YOMTOVE" "$STORDIR"/YomTove.cvs
# actions based on what holiday it is
fi
done
Next_Day
exit
在我当地的 lug 和 linuxquestion.org 的帮助下,我才走到这一步,但我讨厌用我的老脑问题继续骚扰他们。
谢谢。
您要删除第 88 行或第 90 行,它们是不匹配的 fi
。我猜你需要删除第 90 行。
此外,我认为您需要将 case ${ $MONTH } in
替换为 case ${MONTH} in
我正在尝试针对特定条件测试 7 天,并且需要考虑闰年。我认为我的逻辑是正确的,已经重复了 100 次。但出于某种原因,我不断收到同样的错误。
:~$ bin/shabbat/test
bin/shabbat/test: line 90: syntax error near unexpected token `fi'
bin/shabbat/test: line 90: ` fi'
请不要笑得太厉害。我不是程序员。我必须 copy/paste 有效的代码并更改它尝试让它做我想做的事。
#!/bin/bash
STORDIR="${HOME}/bin/shabbat/data"
DAY=28
MONTH=1
YEAR=2016
# Calculate next day accounting for leap years
function Next_Day
{
case ${ $MONTH } in
1)
FULL="31"
;;
2)
FULL="28"
;;
3)
FULL="31"
;;
4)
FULL="30"
;;
5)
FULL="31"
;;
6)
FULL="30"
;;
7)
FULL="31"
;;
8)
FULL="31"
;;
9)
FULL="30"
;;
10)
FULL="31"
;;
11)
FULL="30"
;;
12)
FULL="31"
;;
esac
if [[ "$DAY" -le "27" ]]; then
(( DAY++ ))
exit
elif [[ ${MONTH} == "2" ]]; then
rem1=$((YEAR%4))
rem2=$((YEAR%100))
rem3=$((YEAR%400))
if [ ${rem3} = "0" ]; then
$FULL="29"
exit
fi
if [ ${rem2} = "0" -a ${rem3} != "0" ]; then
# echo "$YEAR Is Not A Leap Year"
exit
fi
if [ ${rem1} = "0" -a ${rem2} != "0" ]; then
# echo "$YEAR Is A Leap Year"
$FULL="29"
else
# echo "$YEAR Is Not A Leap Year"
exit
fi
if [ ${DAY} = ${FULL} -a ${MONTH} -lt "12" ]; then
(( MONTH++ ))
(( DAY++ ))
exit
fi
elif [ ${DAY} = ${FULL} -a ${MONTH} = "12" ]; then
(( YEAR++ ))
let MONTH=1
let DAY=1
exit
fi
exit
fi
}
#################
# # Main Code # #
#################
for (( i = 1; i < 7; i++)); do
YOMTOVE=$(hdate -dhq $DAY $MONTH $YEAR | awk 'NR==3')
echo "$YOMTOVE"
if [[ -n "$YOMTOVE" ]]; then
grep ^"$YOMTOVE" "$STORDIR"/YomTove.cvs
# actions based on what holiday it is
fi
done
Next_Day
exit
在我当地的 lug 和 linuxquestion.org 的帮助下,我才走到这一步,但我讨厌用我的老脑问题继续骚扰他们。
谢谢。
您要删除第 88 行或第 90 行,它们是不匹配的 fi
。我猜你需要删除第 90 行。
此外,我认为您需要将 case ${ $MONTH } in
替换为 case ${MONTH} in