Shell Scripting Help
Nils Kassube
kassube at gmx.net
Tue May 15 06:12:14 UTC 2007
Ghodmode wrote:
> # Let the shell do the basic math instead of calling an external
> program
I like your logic, although I'd say "Better let date do the math instead
of writing a faulty script" :)
> if [ $DAY -eq 0 ]; then
> MONTH=$(( MONTH - 1 ))
> [ $MONTH -eq 0 ] && $MONTH = 12
E.g. the last line should be
[ $MONTH -eq 0 ] && MONTH=12 && YEAR=$(($YEAR - 1))
but this is untested, so it might be faulty as well.
> On 5/15/07, Nils Kassube <kassube at gmx.net> wrote:
> > How about this one?
>
> echo "1 day ago was: $(date -d yesterday '+%m %d %Y')"
>
>
> Thanks, Nils.. I didn't know date had that argument :)
That's the beauty of the date command -- it understands many verbose
descriptions of the date / time to display. Meanwhile i think it would
have been more consistent to write the command like this:
echo "1 day ago was: $(date -d '1 day ago' '+%m %d %Y')"
Nils
More information about the ubuntu-users
mailing list