如何提高猛砸一个循环中的一个日期 [英] How to increase a date within a loop in Bash
问题描述
我工作的这个功能基本上适用于2日期。
一个是当前的日期,另一个是1个月前日期。
继承人的code:
dateTale = $(日期-d$(日期) - 1-月+%Y%M%D)
现在= $(日期+%Y%M%D)
而[$ dateTale-lt$现在]
做
$ dateTale = $(日期-d$ dateTale + 1天+%Y%M%D)
回声,并称
DONE
正如你可以看到我试图增加dateTale,直至达到当前的日期,BUIT我不断收到错误消息:[20120703:命令未找到
我试图从while语句相同的错误消息中,但仍去除引号。
但是,即使解决了的时候,会-lt计算实际日期值或数字的?
任何意见?
空间使用 [
命令时是很重要的:
而[$ dateTale-lt$现在]
此外,你不分配给变量时(与Perl或PHP)使用$
dateTale = $(日期-d$ dateTale + 1天+%Y%M%D)
I'm working on this function that basically works on 2 dates. One is the current date, the other is a 1 month ago date. Heres the code:
dateTale=$(date -d "$(date) - 1 month" +%Y%m%d)
now=$(date +%Y%m%d)
while ["$dateTale" -lt "$now"]
do
$dateTale=$(date -d "$dateTale + 1 day" +%Y%m%d)
echo "adding"
done
As you can see i'm trying to increase dateTale until it reaches the current date, buit i keep on getting the error message: [20120703: command not found I tried removing the quotes from within the while statement but still same error message. But even when resolved, will -lt calculate the actual date value or the numeric one?
Any advice?
Spaces are important when using the [
command:
while [ "$dateTale" -lt "$now" ]
Also, you don't use the '$' when assigning to variables (unlike perl or php):
dateTale=$(date -d "$dateTale + 1 day" +%Y%m%d)
这篇关于如何提高猛砸一个循环中的一个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!