【发布时间】:2017-01-12 09:27:17
【问题描述】:
下面是我的代码。
#!/bin/ksh
curdate=$(date '+%d%h,%Y')
while read line;
do
echo "$line" > new10.txt
str0=$(cut -f 2 new10.txt)
str01=$(cut -f 1 -d ',' new10.txt)
str1=$(cut -f 2 -d ',' new10.txt)
str2=$(cut -c 3 $str1)
if [ $str2=':' ];
then
str2=',2016'
finalstr=$str01$str2
if [ '01jan2017' -le $finalstr -le $curdate ];
then
finalstr1=$str01',2017'
else
finalstr1=$str01',2016'
echo $finalstr1 > datefinal.txt
fi
done < /export/home/islams/PISAS/userwiseutil/date.txt
我收到以下错误:
date1.sh:第 22 行:意外令牌附近的语法错误 done'
date1.sh: line 22:done
【问题讨论】:
-
您还没有关闭您的
if语句之一。我看到两个if,只有一个fi。此外,您应该使用缩进使内容更易于阅读。 -
看,我添加了缩进,问题就很明显了。发到stackoverflow前请缩进,看你的帖子更愉快,会解决这种错误
-
非常感谢并为我的愚蠢错误感到抱歉。请告诉我用于比较范围内日期的 if 语句是否正确?
-
你不能在一个 if 语句中比较 3 件事。考虑使用格式 yyyymmdd,这将使比较日期更容易。