unexpected result from sh script with `date`
gs_stoller at juno.com
gs_stoller at juno.com
Tue Feb 6 02:36:05 UTC 2007
On Fri, 2 Feb 2007 22:11:56 +1100, Tigger <tigger at lvlworld.com> wrote
> Hello, the following simply sh script is outputting unexpected results.
> Any idea why?
> --script--
> #!/bin/sh
> started=`date`
> echo "Started at: $started"
> echo "Finished : "`date`
> exit
> --output--
> Started at: Fri Feb 2 22:13:51 EST 2007
> Finished : Fri Feb 2 22:13:51 EST 2007
> --problem--
> Between 'Feb' and '2', there is two spaces on the 'Started at' line,
> however the 'Finished' one only has 1 space.
> I know this sounds picky, but I was not expecting this at all.
It is not a problem with date , it did the same thing both times. The echo command coalesces consecutive blank space characters down to one blank unless they are quoted. If you change the line
echo "Finished : "`date`
to be
echo "Finished : `date`"
it will do what you expect.
[snip]
More information about the freebsd-questions
mailing list