News for hackers. Stuff that matters.
Re:Bash Retry Function with Exponential Backoff by cmckn on Thursday December 29, 2022 @06:46PM (#34179687)
There is a gotcha here if you use:

  set -o errexit
Because *any bash arithmetic expression that evaluates to zero returns the exit code of 1*.

So this works:

  #!/usr/bin/env bash
  set -o errexit
  i=0
  ((++i))
  echo $i # 1 will be printed to stdout
But this doesn't:

  #!/usr/bin/env bash
  set -o errexit
  i=0
  ((i++)) # terminates here with $? of 1
  echo $i
The relevant doc is for `let`:

       let arg [arg ...]
              Each arg is an arithmetic expression to be evaluated (see
              ARITHMETIC EVALUATION above).  If the last arg evaluates
              to 0, let returns 1; 0 is returned otherwise.
https://www.gnu.org/software/bash/manual/bash.html#index-let
Re:Bash Retry Function with Exponential Backoff by chubot on Thursday December 29, 2022 @08:22PM (#34180492)
Yeah it's best to just use POSIX shell arithmetic, and not be clever, and not the other 2 ways bash has to do it! THat is:

    i=$((i + 1))
The (( )) construct, without the $, is different, and it's also not POSIX. It has the gotchas around the exit code, which a plain assignment doesn't have.