sh man page ....

William A. Mahaffey III wam at hiwaay.net
Mon Oct 13 12:08:25 UTC 2014


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 at 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 at 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 at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at 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.



More information about the freebsd-questions mailing list