Redian新闻
>
A Question on Shell (ksh) programming
avatar
A Question on Shell (ksh) programming# Unix - 噫吁兮,危乎高哉
c*t
1
I tried to get full date string of yesterday with format YYYYMMDD.
The following function works fine except the end of each month. Could
anybody tell me why? and how to fix?
Thanks
#!/usr/bin/ksh
GetDate ()
{
YESTERDAY=$((`date +%d` -1))
MONTH=`date +%m`
YEAR=`date +%Y`
if [ $YESTERDAY -eq "0" ]
then
MONTH=$((MONTH-1))
if [ $MONTH -eq "0" ]
then
MONTH=12
YEAR=$((YEAR-1))
fi
set `cal $MONTH $YEAR`
shift $(($# - 1))
avatar
t*u
2
i commented out "GetDate ()" and "{}", made it into a script, it works
correctly on my machine.

【在 c**t 的大作中提到】
: I tried to get full date string of yesterday with format YYYYMMDD.
: The following function works fine except the end of each month. Could
: anybody tell me why? and how to fix?
: Thanks
: #!/usr/bin/ksh
: GetDate ()
: {
: YESTERDAY=$((`date +%d` -1))
: MONTH=`date +%m`
: YEAR=`date +%Y`

avatar
c*t
3
Did you change your system date to 11/01/2003 or 10/01/2003?
As I stated it works fine except the last day of a month.

【在 t*u 的大作中提到】
: i commented out "GetDate ()" and "{}", made it into a script, it works
: correctly on my machine.

avatar
t*u
4
yea, set the date to 10/01/2003, it prints "2003930".

【在 c**t 的大作中提到】
: Did you change your system date to 11/01/2003 or 10/01/2003?
: As I stated it works fine except the last day of a month.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。