From owner-freebsd-questions@FreeBSD.ORG Mon Oct 13 13:13:18 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 05562F54 for ; Mon, 13 Oct 2014 13:13:18 +0000 (UTC) Received: from mail-wi0-x233.google.com (mail-wi0-x233.google.com [IPv6:2a00:1450:400c:c05::233]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 81ED212D for ; Mon, 13 Oct 2014 13:13:17 +0000 (UTC) Received: by mail-wi0-f179.google.com with SMTP id d1so7401789wiv.6 for ; Mon, 13 Oct 2014 06:13:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=date:from:to:subject:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; bh=BmNi0OOvBQ533kAVIPyyB1bHr16NsEIg67vLHtVTMW0=; b=O353CgrQXxJrkwqiKRERx8YafpHXeIAFMHV+uyGTzIe+y6GYcRUjuTc8L8N8bnKnpa RFTwh7BqxRAd4Is9gjyyt2aUz75vcBN4ijc2nKweE0fIZ1KZ7gO3KBjaKjekrMtQXCVo Mo87Dd5wQ13ZNMBV3kQ9vTesI95WoXqeGBLSHh3Cf9dJorV22DwoOxjv9ht3Qd2Nhvxs hZ3xZ/bQoe52RowY/lgCDaVmaXvcAaXZehrlx0RWvRG3aYgnSokcY8Og87wEdInl8+a3 tObLp3dwVMFZYpiNFtZ2o5I3PjqUNrnf9yasFQkkT2MkrQ+CAJROE8Y43KE8SL8PM7yg Bchg== X-Received: by 10.180.96.226 with SMTP id dv2mr811435wib.48.1413205993470; Mon, 13 Oct 2014 06:13:13 -0700 (PDT) Received: from gumby.homeunix.com (5ec1f671.skybroadband.com. [94.193.246.113]) by mx.google.com with ESMTPSA id p1sm16621034wjy.22.2014.10.13.06.13.12 for (version=SSLv3 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Oct 2014 06:13:12 -0700 (PDT) Date: Mon, 13 Oct 2014 14:13:09 +0100 From: RW To: freebsd-questions@freebsd.org Subject: Re: sh man page .... Message-ID: <20141013141309.16b0edb8@gumby.homeunix.com> In-Reply-To: <543BC227.50004@hiwaay.net> References: <5437FB8B.9080008@hiwaay.net> <20141010183814.3ae32a05@gumby.homeunix.com> <5438755B.2000108@hiwaay.net> <20141013124649.4082d94f@gumby.homeunix.com> <543BC227.50004@hiwaay.net> X-Mailer: Claws Mail 3.10.1 (GTK+ 2.24.22; amd64-portbld-freebsd10.0) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Oct 2014 13:13:18 -0000 On Mon, 13 Oct 2014 07:14:31 -0500 William A. Mahaffey III wrote: > On 10/13/14 06:46, RW wrote: > > On Fri, 10 Oct 2014 19:10:03 -0500 > > The problem here is that you have: > > > > [ 0 -lt $(($slept)) ] > > > > If you change it to the normal usage > > > > [ 0 -lt $((slept)) ] > > > > it works as expected. > > > > Is there any particular reason for the extra "$"? > > > > I guess the difference is not in the handling of uninitialised > > variables, but specifically in the handling of $(()) which is an > > error in sh, but not is bash. > > _______________________________________________ > > freebsd-questions@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > > To unsubscribe, send any mail to > > "freebsd-questions-unsubscribe@freebsd.org" > > > > Good question. I am *not* a bash/shell wiz, but I think the extra "$" > was needed to get bash to behave (Linux, FC14 64-bit, i.e. a bit > dated). Not 100% on that, but pretty sure .... I suspect you are mixing-up the inner and outer "$". $((slept)) will evaluate to a number whether or not slept is defined, which is what is needed. I can't see that the inner "$" in $(($slept) does anything useful in bash. Just to be clear what I think is happening is that $(($slept) is equivalent to $((slept)) when slept is defined and $(()) when it isn't. And in bash $ echo $(( x )) 0 $ echo $(( )) 0 and sh $ echo $(( x )) 0 $ echo $(( )) arithmetic expression: expecting primary: " " This is a much less significant difference than the handling of uninitialized variables would be. $x in POSIX arithmetic is almost always going to be a mistake and one that may produce hard to spot bugs, so I think treating $(( )) as an error is very sensible.