端末から日付を読み取り、シェルスクリプトを使って現在の日付と比較する適切な方法を知りたいのですが、
私は以下のスクリプトを持っています、
a=`date +%Y-%m-%d`
while [ 1 ] ; do
echo "Enter Date"
read todate
if [ $todate < $a ];then
break;
fi
echo "todate greater than curDate"
done
期待どおりに実行されていません。私を助けてください。
アップデート
これが私の最終バージョンです。
#! /bin/bash
DATE=$(date '+%s')
while [ 1 ] ; do
echo "Enter Date[DD MM YYYY]:"
read D M Y
THIS=$(date -d "$Y-$M-$D" '+%s')
if (( THIS < DATE )) ; then
break
fi
done
みんな、ありがとう!