2

我正在尝试在 bash 中编写一个测试,以检查是否输入了正确的日期(或者根本没有输入日期)。这是我正在尝试做的事情:

tDate=$(lastCOB)
tDateOkay=0

until [ $tDateOkay -eq 1 ] ; do
    read -p "Please Enter date for search.  Use format: Date (YYYYMMDD): " -e -i "$tdate" tDate
        if [[ -z "$tDate" || {check for valid YYMMDD format}]] ; then
                echo "Invalid date. Please enter date in the correct format."
        elif [[ $tDate -gt $(today)|| $tdate -eq $(today) ]] ; then
                echo "Date must be in the past.  Please try again."
        else
            tDateOkay=1
        fi
done

日期必须是过去的,并且必须以正确的格式写入,否则将无法从正确的文件夹中提取数据。谢谢。

4

1 回答 1

1
# other stuff
elif (( `date +%s -d $tDate` >= `date +%s` ))
then
  echo 'Date must be in the past.  Please try again.'
  # other stuff
于 2013-05-07T15:48:54.467 回答