Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Feb 2007 02:34:11 GMT
From:      "gs_stoller@juno.com" <gs_stoller@juno.com>
To:        tigger@lvlworld.com
Cc:        freebsd-questions@freebsd.org
Subject:   RE:  unexpected result from sh script with `date`
Message-ID:  <20070205.183452.10246.1290258@webmail30.nyc.untd.com>

next in thread | raw e-mail | index | archive | help
On  Fri, 2 Feb 2007 22:11:56 +1100,  Tigger <tigger@lvlworld.com>  wrote=

> Hello, the following simply sh script is outputting unexpected results=
.
> Any idea why?
> --script--
> #!/bin/sh
> started=3D`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]
 =




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070205.183452.10246.1290258>