Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 Oct 2014 12:46:49 +0100
From:      RW <rwmaillists@googlemail.com>
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>

next in thread | previous in thread | raw e-mail | index | archive | help
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. 



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