From owner-freebsd-questions@FreeBSD.ORG Mon Oct 13 12:08:25 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id F384CF8F for ; Mon, 13 Oct 2014 12:08:24 +0000 (UTC) Received: from fly.hiwaay.net (fly.hiwaay.net [216.180.54.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id BE9CBA59 for ; Mon, 13 Oct 2014 12:08:24 +0000 (UTC) Received: from kabini1.local (rbn1-216-180-19-48.adsl.hiwaay.net [216.180.19.48]) (authenticated bits=0) by fly.hiwaay.net (8.13.8/8.13.8/fly) with ESMTP id s9DC8GVr022348 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Mon, 13 Oct 2014 07:08:17 -0500 Message-ID: <543BC227.50004@hiwaay.net> Date: Mon, 13 Oct 2014 07:14:31 -0500 From: "William A. Mahaffey III" User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 MIME-Version: 1.0 To: freebsd-questions@freebsd.org Subject: Re: sh man page .... References: <5437FB8B.9080008@hiwaay.net> <20141010183814.3ae32a05@gumby.homeunix.com> <5438755B.2000108@hiwaay.net> <20141013124649.4082d94f@gumby.homeunix.com> In-Reply-To: <20141013124649.4082d94f@gumby.homeunix.com> Content-Type: text/plain; charset=windows-1252; format=flowed 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 12:08:25 -0000 On 10/13/14 06:46, RW wrote: > On Fri, 10 Oct 2014 19:10:03 -0500 > William A. Mahaffey III wrote: > > >> Straight out of the script which is failing. Under linux, if I call >> the script w/ no '-s #' option, the variable 'slept' is not set, & >> linux (or more accurately linux bash) evaluates that to the value oif >> zero (0). >> >> >> [wam@kabini1, ~, 7:07:22pm] 386 % sh >> $ if [ 0 -lt $(($slept)) ] ; then echo -n "$cmd: sleeping $slept secs >> ...." ; sleep $(($slept)) ; echo " done." ; fi >> arithmetic expression: expecting primary: "" >> [wam@kabini1, ~, 7:07:45pm] 387 % > > 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 .... -- William A. Mahaffey III ---------------------------------------------------------------------- "The M1 Garand is without doubt the finest implement of war ever devised by man." -- Gen. George S. Patton Jr.