From owner-freebsd-questions@FreeBSD.ORG Fri Feb 2 12:48:36 2007 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id BD64B16A403 for ; Fri, 2 Feb 2007 12:48:36 +0000 (UTC) (envelope-from j65nko@gmail.com) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.225]) by mx1.freebsd.org (Postfix) with ESMTP id 6D1C413C461 for ; Fri, 2 Feb 2007 12:48:36 +0000 (UTC) (envelope-from j65nko@gmail.com) Received: by wr-out-0506.google.com with SMTP id 69so720420wra for ; Fri, 02 Feb 2007 04:48:33 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ng3qBxeGO/nGO4xirW80dIK3zDD/rwxx7O6el/4t5d/RP+mIRrM/BtShF9xbU6aCifDG8b/cZlRkCOzGmyf+PYOiurGTt6hZVFI3QIx+SaFS13MaNYnxfzDw0SKa7DrQrQN8N3oIn8rh0TPn3qCr1mSKw13zB1N0l6qswgw1JyM= Received: by 10.78.204.7 with SMTP id b7mr821988hug.1170420511887; Fri, 02 Feb 2007 04:48:31 -0800 (PST) Received: by 10.78.158.9 with HTTP; Fri, 2 Feb 2007 04:48:31 -0800 (PST) Message-ID: <19861fba0702020448u50ac68adqf205a3cd001e901f@mail.gmail.com> Date: Fri, 2 Feb 2007 13:48:31 +0100 From: J65nko To: Tigger In-Reply-To: <20070202111156.GA41151@lilypie.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20070202111156.GA41151@lilypie.com> Cc: freebsd-questions@freebsd.org Subject: Re: unexpected result from sh script with `date` X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Feb 2007 12:48:36 -0000 On 2/2/07, Tigger 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. > > uname -a > FreeBSD piglet 6.2-STABLE FreeBSD 6.2-STABLE #0: Fri Jan 19 04:13:20 EST > 2007 tigger@piglet:/usr/obj/usr/src/sys/PIGLET i386 The same on OpenBSD here (ksh) OpenBSD 4.0-current (GENERIC) #1194: Thu Nov 2 16:32:12 MST 2006 deraadt@i386.openbsd.org:/usr/src/sys/arch/i386/compile/GENERIC It seems to depend whether the command substitution is within the quote-delimited string, for 'echo' or outside that string, in other words on its own. ------- script---------- #!/bin/sh started=$(date) echo "\$started within \" delimited string for echo" echo "Started at: $started" echo "Command substitution \$(date) within \" delimited string for echo" echo "Finished : $(date)" echo "Command substitution \$(date) outside \" delimited string for echo" echo "Finished : "$(date) echo "Command substitution \`date\` outside \" delimited string for echo" echo "Finished : "$(date) ----------------------------------- Output: ------------------- $started within " delimited string for echo Started at: Fri Feb 2 13:46:07 CET 2007 Command substitution $(date) within " delimited string for echo Finished : Fri Feb 2 13:46:07 CET 2007 Command substitution $(date) outside " delimited string for echo Finished : Fri Feb 2 13:46:07 CET 2007 Command substitution `date` outside " delimited string for echo Finished : Fri Feb 2 13:46:07 CET 2007 --------------------------------------- Embedded inside the string there are two spaces between Feb and the 2, as "stand-alone" there is only one space. Strange indeed ;) J65nko