[[ 0*10%300 ]] works on AIX 6.1 but not on AIX 7.1 (ksh)












1














I have a ksh93 script that I'm migrating from AIX 6.1 to AIX 7.1



It's failing on 7.1 but works fine on 6.1. Here's a snippet of the important parts.



integer f_count=0
. . .
. . .
. . .
if [[ ($f_count*$sleep_interval%$alarm_interval -eq 0 ) && $f_count > 0 ]]
then


When it hits the "if" I get



line 191: *10%300: arithmetic syntax error



I decided to simplify it by typing this at the command prompt.



AIX 7.1> integer x=1          
AIX 7.1> [[ $x*10%300 -eq 0 ]]
AIX 7.1> print $?
1
AIX 7.1> integer x=0
AIX 7.1> [[ $x*10%300 -eq 0 ]]
-ksh93: *10%300: arithmetic syntax error


AIX 6.1> integer x=1
AIX 6.1> [[ $x*10%300 -eq 0 ]]
AIX 6.1> print $?
1
AIX 6.1> integer x=0
AIX 6.1> [[ $x*10%300 -eq 0 ]]
AIX 6.1> print $?
0


To show it's ksh93 on AIX 6.1 I did this.



asdlkfjasd
-ksh93: asdlkfjasd: not found.


If I move the 0 value so it's not first, it works as expected.



AIX 7.1> integer x=1            
AIX 7.1> [[ 10*$x%300 -eq 0 ]]
AIX 7.1> print $?
1
AIX 7.1> integer x=0
AIX 7.1> [[ 10*$x%300 -eq 0 ]]
AIX 7.1> print $?
0


This will fix my issue as I know the 2nd and 3rd variables in my original equation will never be 0.



Is this showing an AIX 7.1 bug?










share|improve this question
























  • Whats the content of ${.sh.version} on both systems?
    – Stéphane Chazelas
    Nov 9 '16 at 15:39










  • (on mine: AIX6 = Version M-12/28/93e; provided by bos.rte.shell 6.1.9.45, AIX7 = Version M 93t+ 2009-05-01; provided by bos.rte.shell 7.1.3.45)
    – Jeff Schaller
    Nov 9 '16 at 15:53












  • If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
    – Jeff Schaller
    Apr 23 '17 at 13:03
















1














I have a ksh93 script that I'm migrating from AIX 6.1 to AIX 7.1



It's failing on 7.1 but works fine on 6.1. Here's a snippet of the important parts.



integer f_count=0
. . .
. . .
. . .
if [[ ($f_count*$sleep_interval%$alarm_interval -eq 0 ) && $f_count > 0 ]]
then


When it hits the "if" I get



line 191: *10%300: arithmetic syntax error



I decided to simplify it by typing this at the command prompt.



AIX 7.1> integer x=1          
AIX 7.1> [[ $x*10%300 -eq 0 ]]
AIX 7.1> print $?
1
AIX 7.1> integer x=0
AIX 7.1> [[ $x*10%300 -eq 0 ]]
-ksh93: *10%300: arithmetic syntax error


AIX 6.1> integer x=1
AIX 6.1> [[ $x*10%300 -eq 0 ]]
AIX 6.1> print $?
1
AIX 6.1> integer x=0
AIX 6.1> [[ $x*10%300 -eq 0 ]]
AIX 6.1> print $?
0


To show it's ksh93 on AIX 6.1 I did this.



asdlkfjasd
-ksh93: asdlkfjasd: not found.


If I move the 0 value so it's not first, it works as expected.



AIX 7.1> integer x=1            
AIX 7.1> [[ 10*$x%300 -eq 0 ]]
AIX 7.1> print $?
1
AIX 7.1> integer x=0
AIX 7.1> [[ 10*$x%300 -eq 0 ]]
AIX 7.1> print $?
0


This will fix my issue as I know the 2nd and 3rd variables in my original equation will never be 0.



Is this showing an AIX 7.1 bug?










share|improve this question
























  • Whats the content of ${.sh.version} on both systems?
    – Stéphane Chazelas
    Nov 9 '16 at 15:39










  • (on mine: AIX6 = Version M-12/28/93e; provided by bos.rte.shell 6.1.9.45, AIX7 = Version M 93t+ 2009-05-01; provided by bos.rte.shell 7.1.3.45)
    – Jeff Schaller
    Nov 9 '16 at 15:53












  • If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
    – Jeff Schaller
    Apr 23 '17 at 13:03














1












1








1







I have a ksh93 script that I'm migrating from AIX 6.1 to AIX 7.1



It's failing on 7.1 but works fine on 6.1. Here's a snippet of the important parts.



integer f_count=0
. . .
. . .
. . .
if [[ ($f_count*$sleep_interval%$alarm_interval -eq 0 ) && $f_count > 0 ]]
then


When it hits the "if" I get



line 191: *10%300: arithmetic syntax error



I decided to simplify it by typing this at the command prompt.



AIX 7.1> integer x=1          
AIX 7.1> [[ $x*10%300 -eq 0 ]]
AIX 7.1> print $?
1
AIX 7.1> integer x=0
AIX 7.1> [[ $x*10%300 -eq 0 ]]
-ksh93: *10%300: arithmetic syntax error


AIX 6.1> integer x=1
AIX 6.1> [[ $x*10%300 -eq 0 ]]
AIX 6.1> print $?
1
AIX 6.1> integer x=0
AIX 6.1> [[ $x*10%300 -eq 0 ]]
AIX 6.1> print $?
0


To show it's ksh93 on AIX 6.1 I did this.



asdlkfjasd
-ksh93: asdlkfjasd: not found.


If I move the 0 value so it's not first, it works as expected.



AIX 7.1> integer x=1            
AIX 7.1> [[ 10*$x%300 -eq 0 ]]
AIX 7.1> print $?
1
AIX 7.1> integer x=0
AIX 7.1> [[ 10*$x%300 -eq 0 ]]
AIX 7.1> print $?
0


This will fix my issue as I know the 2nd and 3rd variables in my original equation will never be 0.



Is this showing an AIX 7.1 bug?










share|improve this question















I have a ksh93 script that I'm migrating from AIX 6.1 to AIX 7.1



It's failing on 7.1 but works fine on 6.1. Here's a snippet of the important parts.



integer f_count=0
. . .
. . .
. . .
if [[ ($f_count*$sleep_interval%$alarm_interval -eq 0 ) && $f_count > 0 ]]
then


When it hits the "if" I get



line 191: *10%300: arithmetic syntax error



I decided to simplify it by typing this at the command prompt.



AIX 7.1> integer x=1          
AIX 7.1> [[ $x*10%300 -eq 0 ]]
AIX 7.1> print $?
1
AIX 7.1> integer x=0
AIX 7.1> [[ $x*10%300 -eq 0 ]]
-ksh93: *10%300: arithmetic syntax error


AIX 6.1> integer x=1
AIX 6.1> [[ $x*10%300 -eq 0 ]]
AIX 6.1> print $?
1
AIX 6.1> integer x=0
AIX 6.1> [[ $x*10%300 -eq 0 ]]
AIX 6.1> print $?
0


To show it's ksh93 on AIX 6.1 I did this.



asdlkfjasd
-ksh93: asdlkfjasd: not found.


If I move the 0 value so it's not first, it works as expected.



AIX 7.1> integer x=1            
AIX 7.1> [[ 10*$x%300 -eq 0 ]]
AIX 7.1> print $?
1
AIX 7.1> integer x=0
AIX 7.1> [[ 10*$x%300 -eq 0 ]]
AIX 7.1> print $?
0


This will fix my issue as I know the 2nd and 3rd variables in my original equation will never be 0.



Is this showing an AIX 7.1 bug?







ksh aix test






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 '16 at 15:21









Jeff Schaller

38.9k1053125




38.9k1053125










asked Nov 9 '16 at 13:52









Scavenger

656




656












  • Whats the content of ${.sh.version} on both systems?
    – Stéphane Chazelas
    Nov 9 '16 at 15:39










  • (on mine: AIX6 = Version M-12/28/93e; provided by bos.rte.shell 6.1.9.45, AIX7 = Version M 93t+ 2009-05-01; provided by bos.rte.shell 7.1.3.45)
    – Jeff Schaller
    Nov 9 '16 at 15:53












  • If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
    – Jeff Schaller
    Apr 23 '17 at 13:03


















  • Whats the content of ${.sh.version} on both systems?
    – Stéphane Chazelas
    Nov 9 '16 at 15:39










  • (on mine: AIX6 = Version M-12/28/93e; provided by bos.rte.shell 6.1.9.45, AIX7 = Version M 93t+ 2009-05-01; provided by bos.rte.shell 7.1.3.45)
    – Jeff Schaller
    Nov 9 '16 at 15:53












  • If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
    – Jeff Schaller
    Apr 23 '17 at 13:03
















Whats the content of ${.sh.version} on both systems?
– Stéphane Chazelas
Nov 9 '16 at 15:39




Whats the content of ${.sh.version} on both systems?
– Stéphane Chazelas
Nov 9 '16 at 15:39












(on mine: AIX6 = Version M-12/28/93e; provided by bos.rte.shell 6.1.9.45, AIX7 = Version M 93t+ 2009-05-01; provided by bos.rte.shell 7.1.3.45)
– Jeff Schaller
Nov 9 '16 at 15:53






(on mine: AIX6 = Version M-12/28/93e; provided by bos.rte.shell 6.1.9.45, AIX7 = Version M 93t+ 2009-05-01; provided by bos.rte.shell 7.1.3.45)
– Jeff Schaller
Nov 9 '16 at 15:53














If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
– Jeff Schaller
Apr 23 '17 at 13:03




If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
– Jeff Schaller
Apr 23 '17 at 13:03










3 Answers
3






active

oldest

votes


















2














Looks like you've found a bug in ksh93.



I can reproduce it (ksh93u+) with:



$ x= ksh -c '[[ 0*1 -eq 5 ]]'
ksh: *1: arithmetic syntax error


It's OK with:



ksh -c '[[ " 0*1" -eq 5 ]]'


though. And it seems it was fixed in ksh93v- (beta) as I can't reproduce it there.



Anyway, I would use:



if ((f_count * sleep_interval % alarm_interval == 0 && f_count > 0)); then


A few notes:




  • inside [[...]], > is for string comparison (where 10 is less than 2 and depending on the locale, -1 may be greater than 0). Use -gt for numerical comparison (though it's better to use ((...))).


  • avoid expanding variables inside arithmetic expressions, as in, use x instead of $x. For instance, compare:



    $ x=-1 ksh -c '((-$x > 0))'
    ksh: --1 > 0: assignment requires lvalue


    with



    $ x=-1 ksh -c '((-x > 0))'
    $


    Or:



    $ x=1+1 ksh -c 'echo "$(($x * 2)) $((x * 2))"'
    3 4







share|improve this answer























  • Thanks for the reply. So, who do I report a bug like this to? Is it an IBM implementation of ksh93 issue, or is there group that maintains ksh and IBM just gets a copy from them? Thanks again.
    – Scavenger
    Nov 9 '16 at 15:40










  • Thanks also for explaining what the [[ ]] are for. I've never seen a good explanation of when to use them, or what the difference is from (( )).
    – Scavenger
    Nov 9 '16 at 15:46






  • 1




    @Scavenger, the future of ksh93 is currently uncertain. Several bugs have been reported at github.com/att/ast/issues, but no work on them. Anyway, it looks like your issue has already been fixed. You could still report the bug to your Unix vendor so that they backport the fix or eventually move to a newer version when they have received enough reports like that.
    – Stéphane Chazelas
    Nov 9 '16 at 15:55





















0














It does appear that ksh's doing something different with the arithmetic expansion; to work around it, I would explicitly use arithmetic substitution, which behaves as expected on both AIX 6 & AIX 7:



...
if [[ ( $((f_count * sleep_interval % alarm_interval)) -eq 0 ) && $f_count -gt 0 ]]
...





share|improve this answer





























    0














    Maybe answer is straight forward; you see problem when a variable at start of an arithmetic expression expands to 0 (zero). This is for left operand of -eq in KSH conditional expression - with -eq being numeric comparison, the operator expects a number as its left hand operand.



    When expanding/evaluating the operands operator needs to do three steps:
    a) expand variables,
    b) strip leading zeroes,
    c) evaluate expression;
    in this order, then you will get the observed problem.



    If the older Shell versions did it in this order:
    a) expand variables,
    b) evaluare expression,
    c) strip leading zeroes;
    then you will not see the problem






    share|improve this answer





















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "106"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f322095%2f010300-works-on-aix-6-1-but-not-on-aix-7-1-ksh%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      Looks like you've found a bug in ksh93.



      I can reproduce it (ksh93u+) with:



      $ x= ksh -c '[[ 0*1 -eq 5 ]]'
      ksh: *1: arithmetic syntax error


      It's OK with:



      ksh -c '[[ " 0*1" -eq 5 ]]'


      though. And it seems it was fixed in ksh93v- (beta) as I can't reproduce it there.



      Anyway, I would use:



      if ((f_count * sleep_interval % alarm_interval == 0 && f_count > 0)); then


      A few notes:




      • inside [[...]], > is for string comparison (where 10 is less than 2 and depending on the locale, -1 may be greater than 0). Use -gt for numerical comparison (though it's better to use ((...))).


      • avoid expanding variables inside arithmetic expressions, as in, use x instead of $x. For instance, compare:



        $ x=-1 ksh -c '((-$x > 0))'
        ksh: --1 > 0: assignment requires lvalue


        with



        $ x=-1 ksh -c '((-x > 0))'
        $


        Or:



        $ x=1+1 ksh -c 'echo "$(($x * 2)) $((x * 2))"'
        3 4







      share|improve this answer























      • Thanks for the reply. So, who do I report a bug like this to? Is it an IBM implementation of ksh93 issue, or is there group that maintains ksh and IBM just gets a copy from them? Thanks again.
        – Scavenger
        Nov 9 '16 at 15:40










      • Thanks also for explaining what the [[ ]] are for. I've never seen a good explanation of when to use them, or what the difference is from (( )).
        – Scavenger
        Nov 9 '16 at 15:46






      • 1




        @Scavenger, the future of ksh93 is currently uncertain. Several bugs have been reported at github.com/att/ast/issues, but no work on them. Anyway, it looks like your issue has already been fixed. You could still report the bug to your Unix vendor so that they backport the fix or eventually move to a newer version when they have received enough reports like that.
        – Stéphane Chazelas
        Nov 9 '16 at 15:55


















      2














      Looks like you've found a bug in ksh93.



      I can reproduce it (ksh93u+) with:



      $ x= ksh -c '[[ 0*1 -eq 5 ]]'
      ksh: *1: arithmetic syntax error


      It's OK with:



      ksh -c '[[ " 0*1" -eq 5 ]]'


      though. And it seems it was fixed in ksh93v- (beta) as I can't reproduce it there.



      Anyway, I would use:



      if ((f_count * sleep_interval % alarm_interval == 0 && f_count > 0)); then


      A few notes:




      • inside [[...]], > is for string comparison (where 10 is less than 2 and depending on the locale, -1 may be greater than 0). Use -gt for numerical comparison (though it's better to use ((...))).


      • avoid expanding variables inside arithmetic expressions, as in, use x instead of $x. For instance, compare:



        $ x=-1 ksh -c '((-$x > 0))'
        ksh: --1 > 0: assignment requires lvalue


        with



        $ x=-1 ksh -c '((-x > 0))'
        $


        Or:



        $ x=1+1 ksh -c 'echo "$(($x * 2)) $((x * 2))"'
        3 4







      share|improve this answer























      • Thanks for the reply. So, who do I report a bug like this to? Is it an IBM implementation of ksh93 issue, or is there group that maintains ksh and IBM just gets a copy from them? Thanks again.
        – Scavenger
        Nov 9 '16 at 15:40










      • Thanks also for explaining what the [[ ]] are for. I've never seen a good explanation of when to use them, or what the difference is from (( )).
        – Scavenger
        Nov 9 '16 at 15:46






      • 1




        @Scavenger, the future of ksh93 is currently uncertain. Several bugs have been reported at github.com/att/ast/issues, but no work on them. Anyway, it looks like your issue has already been fixed. You could still report the bug to your Unix vendor so that they backport the fix or eventually move to a newer version when they have received enough reports like that.
        – Stéphane Chazelas
        Nov 9 '16 at 15:55
















      2












      2








      2






      Looks like you've found a bug in ksh93.



      I can reproduce it (ksh93u+) with:



      $ x= ksh -c '[[ 0*1 -eq 5 ]]'
      ksh: *1: arithmetic syntax error


      It's OK with:



      ksh -c '[[ " 0*1" -eq 5 ]]'


      though. And it seems it was fixed in ksh93v- (beta) as I can't reproduce it there.



      Anyway, I would use:



      if ((f_count * sleep_interval % alarm_interval == 0 && f_count > 0)); then


      A few notes:




      • inside [[...]], > is for string comparison (where 10 is less than 2 and depending on the locale, -1 may be greater than 0). Use -gt for numerical comparison (though it's better to use ((...))).


      • avoid expanding variables inside arithmetic expressions, as in, use x instead of $x. For instance, compare:



        $ x=-1 ksh -c '((-$x > 0))'
        ksh: --1 > 0: assignment requires lvalue


        with



        $ x=-1 ksh -c '((-x > 0))'
        $


        Or:



        $ x=1+1 ksh -c 'echo "$(($x * 2)) $((x * 2))"'
        3 4







      share|improve this answer














      Looks like you've found a bug in ksh93.



      I can reproduce it (ksh93u+) with:



      $ x= ksh -c '[[ 0*1 -eq 5 ]]'
      ksh: *1: arithmetic syntax error


      It's OK with:



      ksh -c '[[ " 0*1" -eq 5 ]]'


      though. And it seems it was fixed in ksh93v- (beta) as I can't reproduce it there.



      Anyway, I would use:



      if ((f_count * sleep_interval % alarm_interval == 0 && f_count > 0)); then


      A few notes:




      • inside [[...]], > is for string comparison (where 10 is less than 2 and depending on the locale, -1 may be greater than 0). Use -gt for numerical comparison (though it's better to use ((...))).


      • avoid expanding variables inside arithmetic expressions, as in, use x instead of $x. For instance, compare:



        $ x=-1 ksh -c '((-$x > 0))'
        ksh: --1 > 0: assignment requires lvalue


        with



        $ x=-1 ksh -c '((-x > 0))'
        $


        Or:



        $ x=1+1 ksh -c 'echo "$(($x * 2)) $((x * 2))"'
        3 4








      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 9 '16 at 15:52

























      answered Nov 9 '16 at 15:34









      Stéphane Chazelas

      300k54564913




      300k54564913












      • Thanks for the reply. So, who do I report a bug like this to? Is it an IBM implementation of ksh93 issue, or is there group that maintains ksh and IBM just gets a copy from them? Thanks again.
        – Scavenger
        Nov 9 '16 at 15:40










      • Thanks also for explaining what the [[ ]] are for. I've never seen a good explanation of when to use them, or what the difference is from (( )).
        – Scavenger
        Nov 9 '16 at 15:46






      • 1




        @Scavenger, the future of ksh93 is currently uncertain. Several bugs have been reported at github.com/att/ast/issues, but no work on them. Anyway, it looks like your issue has already been fixed. You could still report the bug to your Unix vendor so that they backport the fix or eventually move to a newer version when they have received enough reports like that.
        – Stéphane Chazelas
        Nov 9 '16 at 15:55




















      • Thanks for the reply. So, who do I report a bug like this to? Is it an IBM implementation of ksh93 issue, or is there group that maintains ksh and IBM just gets a copy from them? Thanks again.
        – Scavenger
        Nov 9 '16 at 15:40










      • Thanks also for explaining what the [[ ]] are for. I've never seen a good explanation of when to use them, or what the difference is from (( )).
        – Scavenger
        Nov 9 '16 at 15:46






      • 1




        @Scavenger, the future of ksh93 is currently uncertain. Several bugs have been reported at github.com/att/ast/issues, but no work on them. Anyway, it looks like your issue has already been fixed. You could still report the bug to your Unix vendor so that they backport the fix or eventually move to a newer version when they have received enough reports like that.
        – Stéphane Chazelas
        Nov 9 '16 at 15:55


















      Thanks for the reply. So, who do I report a bug like this to? Is it an IBM implementation of ksh93 issue, or is there group that maintains ksh and IBM just gets a copy from them? Thanks again.
      – Scavenger
      Nov 9 '16 at 15:40




      Thanks for the reply. So, who do I report a bug like this to? Is it an IBM implementation of ksh93 issue, or is there group that maintains ksh and IBM just gets a copy from them? Thanks again.
      – Scavenger
      Nov 9 '16 at 15:40












      Thanks also for explaining what the [[ ]] are for. I've never seen a good explanation of when to use them, or what the difference is from (( )).
      – Scavenger
      Nov 9 '16 at 15:46




      Thanks also for explaining what the [[ ]] are for. I've never seen a good explanation of when to use them, or what the difference is from (( )).
      – Scavenger
      Nov 9 '16 at 15:46




      1




      1




      @Scavenger, the future of ksh93 is currently uncertain. Several bugs have been reported at github.com/att/ast/issues, but no work on them. Anyway, it looks like your issue has already been fixed. You could still report the bug to your Unix vendor so that they backport the fix or eventually move to a newer version when they have received enough reports like that.
      – Stéphane Chazelas
      Nov 9 '16 at 15:55






      @Scavenger, the future of ksh93 is currently uncertain. Several bugs have been reported at github.com/att/ast/issues, but no work on them. Anyway, it looks like your issue has already been fixed. You could still report the bug to your Unix vendor so that they backport the fix or eventually move to a newer version when they have received enough reports like that.
      – Stéphane Chazelas
      Nov 9 '16 at 15:55















      0














      It does appear that ksh's doing something different with the arithmetic expansion; to work around it, I would explicitly use arithmetic substitution, which behaves as expected on both AIX 6 & AIX 7:



      ...
      if [[ ( $((f_count * sleep_interval % alarm_interval)) -eq 0 ) && $f_count -gt 0 ]]
      ...





      share|improve this answer


























        0














        It does appear that ksh's doing something different with the arithmetic expansion; to work around it, I would explicitly use arithmetic substitution, which behaves as expected on both AIX 6 & AIX 7:



        ...
        if [[ ( $((f_count * sleep_interval % alarm_interval)) -eq 0 ) && $f_count -gt 0 ]]
        ...





        share|improve this answer
























          0












          0








          0






          It does appear that ksh's doing something different with the arithmetic expansion; to work around it, I would explicitly use arithmetic substitution, which behaves as expected on both AIX 6 & AIX 7:



          ...
          if [[ ( $((f_count * sleep_interval % alarm_interval)) -eq 0 ) && $f_count -gt 0 ]]
          ...





          share|improve this answer












          It does appear that ksh's doing something different with the arithmetic expansion; to work around it, I would explicitly use arithmetic substitution, which behaves as expected on both AIX 6 & AIX 7:



          ...
          if [[ ( $((f_count * sleep_interval % alarm_interval)) -eq 0 ) && $f_count -gt 0 ]]
          ...






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 '16 at 15:51









          Jeff Schaller

          38.9k1053125




          38.9k1053125























              0














              Maybe answer is straight forward; you see problem when a variable at start of an arithmetic expression expands to 0 (zero). This is for left operand of -eq in KSH conditional expression - with -eq being numeric comparison, the operator expects a number as its left hand operand.



              When expanding/evaluating the operands operator needs to do three steps:
              a) expand variables,
              b) strip leading zeroes,
              c) evaluate expression;
              in this order, then you will get the observed problem.



              If the older Shell versions did it in this order:
              a) expand variables,
              b) evaluare expression,
              c) strip leading zeroes;
              then you will not see the problem






              share|improve this answer


























                0














                Maybe answer is straight forward; you see problem when a variable at start of an arithmetic expression expands to 0 (zero). This is for left operand of -eq in KSH conditional expression - with -eq being numeric comparison, the operator expects a number as its left hand operand.



                When expanding/evaluating the operands operator needs to do three steps:
                a) expand variables,
                b) strip leading zeroes,
                c) evaluate expression;
                in this order, then you will get the observed problem.



                If the older Shell versions did it in this order:
                a) expand variables,
                b) evaluare expression,
                c) strip leading zeroes;
                then you will not see the problem






                share|improve this answer
























                  0












                  0








                  0






                  Maybe answer is straight forward; you see problem when a variable at start of an arithmetic expression expands to 0 (zero). This is for left operand of -eq in KSH conditional expression - with -eq being numeric comparison, the operator expects a number as its left hand operand.



                  When expanding/evaluating the operands operator needs to do three steps:
                  a) expand variables,
                  b) strip leading zeroes,
                  c) evaluate expression;
                  in this order, then you will get the observed problem.



                  If the older Shell versions did it in this order:
                  a) expand variables,
                  b) evaluare expression,
                  c) strip leading zeroes;
                  then you will not see the problem






                  share|improve this answer












                  Maybe answer is straight forward; you see problem when a variable at start of an arithmetic expression expands to 0 (zero). This is for left operand of -eq in KSH conditional expression - with -eq being numeric comparison, the operator expects a number as its left hand operand.



                  When expanding/evaluating the operands operator needs to do three steps:
                  a) expand variables,
                  b) strip leading zeroes,
                  c) evaluate expression;
                  in this order, then you will get the observed problem.



                  If the older Shell versions did it in this order:
                  a) expand variables,
                  b) evaluare expression,
                  c) strip leading zeroes;
                  then you will not see the problem







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 17 '18 at 10:18









                  Jesper Jorgensen

                  1




                  1






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f322095%2f010300-works-on-aix-6-1-but-not-on-aix-7-1-ksh%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Morgemoulin

                      Scott Moir

                      Souastre