Re: Days until Dec 1

From: Larry Starr (starrl_at_dragonone.localdomain)
Date: 03/29/04


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! =-----



Relevant Pages

  • Re: Substring Each Line in a File
    ... know how to echo a substring of each line (I will then redirect each ... This pulls off the 13 characters I am looking for, ... Note that %varname% is the value of varname at the logical line's PARSE ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Substring Each Line in a File
    ... know how to echo a substring of each line (I will then redirect each ... It produces the 13 characters starting at the SECOND ... SETLOCAL ENABLEDELAYEDEXPANSION ... Note that %varname% is the value of varname at the logical line's PARSE ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: From a bash array to a csv file line?
    ... the input from the user at runtime for each and then "echo" their ... values with the date to a csv file so that all would be comma-separated ... for varname in FOO BAR BAZ QUX; ... printf "Enter $varname: " ...
    (comp.unix.shell)