From owner-freebsd-questions@FreeBSD.ORG Mon Oct 13 11:46:56 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 DC06C906 for ; Mon, 13 Oct 2014 11:46:56 +0000 (UTC) Received: from mail-wg0-x234.google.com (mail-wg0-x234.google.com [IPv6:2a00:1450:400c:c00::234]) (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 740F085F for ; Mon, 13 Oct 2014 11:46:56 +0000 (UTC) Received: by mail-wg0-f52.google.com with SMTP id a1so8394331wgh.35 for ; Mon, 13 Oct 2014 04:46:54 -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=1crGgYZPivLNrO0FqKh2rSubHLqbpcZ9DZRBfYj3mTs=; b=xRrEPB9WtyUAg5rKk0G4LKxN6dSbyOVzZdJ61hKq6rtv08CKOMk1kxIlGUkgLUB42g ykWyOYypxSiM4ZgjTCn9Gsrktsjq2BGP95lCs3xOR/RKNQqICb4vMeU6Ov4pppWFvhtI YNEWlmRtDNXzJPOliv0zyAcPaucfiLjlf3G+/Nm9E4Q/GkOTHS+Wqmqxf++Q/DdF+rtz bLsBsgNfQAOm1QQu3x3SFbYALJ91vLQ2TLv+4y4audBBMfaK+0W/v5M2e52uPqHlgoTb F3iL47tfUKNVrsNgEwa66iYqIvcsUNdOw1Lf0XzzxsTOHbYixe97NgsjtVHtFFeGlfys GD5g== X-Received: by 10.180.36.48 with SMTP id n16mr476592wij.6.1413200814749; Mon, 13 Oct 2014 04:46:54 -0700 (PDT) Received: from gumby.homeunix.com (5ec1f671.skybroadband.com. [94.193.246.113]) by mx.google.com with ESMTPSA id ko10sm4993134wjb.48.2014.10.13.04.46.52 for (version=SSLv3 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Oct 2014 04:46:53 -0700 (PDT) Date: Mon, 13 Oct 2014 12:46:49 +0100 From: RW To: freebsd-questions@freebsd.org Subject: Re: sh man page .... Message-ID: <20141013124649.4082d94f@gumby.homeunix.com> In-Reply-To: <5438755B.2000108@hiwaay.net> References: <5437FB8B.9080008@hiwaay.net> <20141010183814.3ae32a05@gumby.homeunix.com> <5438755B.2000108@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 11:46:56 -0000 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.