This topic has been archived. It cannot be replied.
-
工作学习 / IT杂谈 / 一个unix shell script 技术问题(可能是很好的interview问题呦),不能用perl. 用"date" 命令可以得到今天的日期,如 Aug 21,但如何得到昨天的日期,或者一个星期以前的日期呢?
-eglington(eglington);
2002-8-21
(#705677@0)
-
man date, there is probably option letting you input N days ago.
-ingridchao(Ingrid);
2002-8-21
(#705686@0)
-
I've checked, still no clue.
-eglington(eglington);
2002-8-21
(#705699@0)
-
我的TIMEX手表上有日期.
-expertune(将伪劣进行到底);
2002-8-21
(#705687@0)
-
可喜丢了,赫赫
-eglington(eglington);
2002-8-21
(#705701@0)
-
那是CASIO, 你不提我都想不起了...个坏蛋.
-expertune(将伪劣进行到底);
2002-8-21
(#705711@0)
-
On my FreeBSD, I can use 'date -v-1d' to get yesterday's date. But I can't figure out how to use date to do it with Linux or Solaris. Butof course in the shell script you can use date to get today's date first and then calculate yesterday's date.
-dennis2(Dennis);
2002-8-21
{111}
(#705764@0)
-
"of course in the shell script you can use date to get today's date first and then calculate yesterday's date. " How? can I do it within 3 lines?
-eglington(eglington);
2002-8-21
(#705790@0)
-
Which OS? It's easy with BSD or Linux. I still can't figure out Solaris. Or use what noexit posts (well, that's much more than 3 lines but it works).
-dennis2(Dennis);
2002-8-21
(#705849@0)
-
solaris
-eglington(eglington);
2002-8-21
(#706145@0)
-
Solaris' strftime(3C) does not have '%s', 'date' does not have '-r', otherwise it would be much easier.
-dennis2(Dennis);
2002-8-22
(#706552@0)
-
chao lai de.
-noexit(♂江湖夜雨省油灯);
2002-8-21
{1275}
(#705805@0)
-
SHIT!! 这也叫答案?对不起,不是冲你的,只是觉得shell script 太愚蠢了,这样的功能都没做个命令?
-eglington(eglington);
2002-8-21
(#706110@0)
-
unix嘛, 嘿嘿..
-expertune(将伪劣进行到底);
2002-8-21
(#706121@0)
-
Search comp.unix.shell group on the google
-wdding(wdding);
2002-8-21
(#705951@0)
-
看来这是一个很著名的问题,怪不得我想不出来.....GNU 的 date是个解决方案。solaris上有吗?
-eglington(eglington);
2002-8-21
(#706175@0)
-
During the interview. Simply tell the interviewer to get the julian date and minus one and convert it to calender date. Maybe the interviewer doesn't know the answer, either.
-trucluster(Trucluster);
2002-8-23
(#709100@0)
-
答案:
YESTERDAY=`/usr/local/gnu/bin/gdate -d "1 day ago" +20%y-%m-%d`
-eglington(eglington);
2002-8-23
(#709281@0)
-
no gdate installed in my rh 7.3..:D
-speed(如风);
2002-8-23
(#709335@0)