1 Reply Latest reply on Nov 20, 2014 4:33 AM by Jim Wilson

    [ NSH ] Arithmetic expression bug due to outdated ZSH version

    Clement BARRET

      Hi,

       

      Yesterday I found another "bug" from NSH (well, actually, it's an old and already fixed ZSH one).

       

      So, how to reproduce that ? Plain simple :

       

      % echo $(( 1.0 / 3600 ))

      0000.00027777777777777778

       

      You would say "so what ? extra zeros at the beginning ? who cares ?" well... ZSH does (so NSH does)

       

      You're supposed to be able to store that into any variable right ?

       

      # let's try with an integer (that should just round up the arithmetic expression's value)

      % typeset -i my_integer=0;

      % my_integer=$(( 1.0 / 3600 ))

      nsh: bad math expression: operator expected at `.000277777...'

       

      # ok, let's try with a float then

      % typeset -F my_float=0;

      % my_float=$(( 1.0 / 3600 ))

      nsh: bad math expression: operator expected at `.000277777...'

       

       

      So, let's say you have an "untyped" variable, the affectation will work.

       

      % typeset my_youpi;

      % my_youpi=$(( 1.0 / 3600 ));

       

      But what if you want to do some computation with its value ?

       

      % echo $(( my_youpi + 1 ))

      nsh: bad math expression: operator expected at `.000277777...'

       

      For what I've found using google, this ZSH bug seems to have been fixed in version around 4.3.9... Not the latest one so far :/

       

      And the "funny part" in this is that if you have a small enough number, that will go back to "standard" number display and that will work :

       

      % my_float=$(( 1.0 / 36000 ))

      % echo $my_float

      0.0000277778

       

      but yet again :

      % my_float=$(( 1.0 / 3600 ))

      nsh: bad math expression: operator expected at `.000277777...'

       

      For your information :

       

      % version

      BladeLogic RSCD Agent 8.3.02.332 (Release) [Aug 19 2013 09:15:34]

      Copyright (C) 1996-2012 BladeLogic Inc.

      BladeLogic Network Shell 8.3.02.332 (Release) [Aug 19 2013 09:15:34]

      Copyright (C) 1996-2012 BladeLogic Inc.

       

      % nsh --version

      zsh 4.3.4 (i686-pc-linux-gnu)

       

       

      With ZSH (regular) :

       

      Using "new" ZSH, well, latest version I got on our lab RHEL servers (without NSH installed on them)

       

      % zsh --version

      zsh 4.3.10 (x86_64-redhat-linux-gnu)

       

      % typeset -F my_float

      % typeset -i my_integer

      % my_float=$(( 1.0 / 3600 ))

      % echo $my_float

      0.0002777778

      % my_integer=$(( 1.0 / 3600 ))

      % echo $my_integer

      0

       

      Question : Do you know any workaround ?

       

      Appart from doing some ugly :

       

      % my_float=${$(( 1.0 / 3600 ))/#0*0./0.}

      % echo $my_float

      0.0002777778

       

      Regards,

       

      CB

       

      PS : Please let me know if I have to open a ticket for this issue to be fixed.