此问题已在此处有答案:
Compare two dates in shell script(2个答案)
Why does a space in a variable assignment give an error in Bash? [duplicate](3个答案)
Why should there be spaces around '[' and ']' in Bash?(5个答案)
6天前关闭
我需要采取字符串作为输入隐蔽的日期和比较与当前日期在ksh需要的东西如下
read expdate
today=`date +"%d-%m-%Y"`
expD =`$expdate +"%d-%m-%Y"` -- this is not working
if [today -gt expD] ; then
echo "Today is greater"
else
echo " Today is gone"
1条答案
按热度按时间5sxhfpxr1#
由于输入日期格式似乎是MM-DD-YYYY或DD-MM-YYYY,因此没有必要让
date
理解-d
。一个简单的数字比较就足够了:如有必要,在
read
命令中交换m
和d
。为输入格式添加适当的错误检查。