语法错误:意外的文件结尾

语法错误:意外的文件结尾
#!/bin/bash
#organization: Seneca College
#Purpose: Validate a date
#Usage: chkdate year month day
#

year=$1; month=$2; day=$3; extra=$4
if [[ "$year" == "" || "$month" == "" || "$day" == "" ]]; then
        # Not enough data!
        echo Usage: chkdate year month day
        exit 0
fi
if [[ ! ( $year =~ ^[0-9]+$ && $month =~ ^[0-9]+$ && $day =~ ^[0-9]+$ ) ]]; then
        # Date not numeric!
        echo Usage: chkdate year month day
        exit 1
fi
if [[ $year -lt 1 || $year -gt 9999 || $month -lt 1 || $month -gt 12 || $day -lt 1 || $day -gt 31 ]]; then
        # Date out of range!
        echo Usage: chkdate year month day
        exit 2
fi
if [[ ( $month == 1 || $month == 3 || $month == 5 || $month == 7 || $month == 8 || $month == 10 || $month == 12 ) && $day -gt 31 ]]; then
        # Invalid day!
        echo Usage: chkdate year month day
        exit 3
fi
if [[ ( $month == 4 || $month == 6 || $month == 9 || $month == 11 ) && $day -gt 30 ]]; then
        # Invalid day!
        echo Usage: chkdate year month day
        exit 4
fi
if [[ ($month == 9) && ($year == 1752) && ( $day -gt 2) && $day -le 14  ]] ; then
        #invalid day!
        echo Usage: chkdate year month day
        exit 5

date -d $2/$3/$1 > /dev/null 2>&1
if [[ "$@" ]] ; then
        echo "valid date"
else
        echo "not a valid"
fi

它说我的脚本有第 44 行,但我的脚本总行数是 43

答案1

你有一个未终止的if循环。添加一个fifor 这个if循环。

if [[ ($month == 9) && ($year == 1752) && ( $day -gt 2) && $day -le 14  ]] 

添加 后fi,当我运行您的脚本时,这就是我得到的输出。

chkdate 1342 1 21
valid date
chkdate 13as 1 21
Usage: chkdate year month day

相关内容