Re: Days until Dec 1
From: Larry Starr (starrl_at_dragonone.localdomain)
Date: 03/29/04
- Next message: Matty: "Spanning Tree"
- Previous message: natG: "Re: Windows NFS client to access Linux (Fedora & Suse) hosts"
- In reply to: Nyarlathotep: "Days until Dec 1"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 Mar 2004 23:11:13 -0600
In article <c47ro7$jnv$1@news3.bu.edu>, Nyarlathotep wrote:
> How do I print the days until December 1 at startup?. I tried adding
> this to my .bashrc file and it fails.
>
>
>
> echo Today is `date`
> todayis=`date +%j`
> export todayis
> bigeventdate=`date -d '1 Dec' +%j`
> export bigeventdate
> diffdate=$($(bigeventdate)-$(todayis))
> echo You have $diffdate days until the big event
>
>
> -Nyarlathotep
Leading zero's cause bash to treat the variable as Octal,
thus, if you run this before day 100 you get an arithmetic
error.
I'm sure there is a typeset, or declare to fix this but the
brute force fix is:
echo "Today is `date`"
#y=$(date +%Y)
todayis=`date +%j | sed -e 's/^0*//'` # Strip leading zero
bigeventdate=`date -d "Dec 31" +%j`
diffdate=$((${bigeventdate} - ${todayis})) # Fixed Syntax
echo You have $diffdate days until the big event
The sed command strips leading zeros, also your calculation
tries to treat the two variables as commands ( $(varname)
instead of ${varname} or simply $varname), and
leaves out the $(( ... )) builtin for arithmetic.
Enjoy
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
- Next message: Matty: "Spanning Tree"
- Previous message: natG: "Re: Windows NFS client to access Linux (Fedora & Suse) hosts"
- In reply to: Nyarlathotep: "Days until Dec 1"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|