Hi,
I have stumbled upon a bug or something I don't understand while
using the debug trap.
Please run the script at the end.
When debug is turned on, during its execution the program
prints the line number and the line content which returned a non
zero value (error).

If you look at the script, the only line which should cause
a non zero return value is:
  ! :
However the script shows also a non zero return value
before executing the 'true' command.
I can only imagine that the sequence
  if ((0)); then
before the 'else' is the one causing a non zero
return value, however the previous:
  if ((0)); then
    :
  fi
(without the else clause) does not cause a non zero return value.
Is this the expected behavior (and if yes why)?
Or is it a bug?
Seen in bash 4.4 and 5.2.

Giacomo Comes

#!/bin/bash
debugon () {
    trap 'if (($?)); then echo "$((LINENO-1)): $(sed -n "$((LINENO-1))p" "$0")" 
; fi' DEBUG
}
debugoff () {
    trap '' DEBUG
}
debugon

:
! :
if ((1)); then
  :
fi
if ((0)); then
  :
fi
if ((1)); then
  :
else
  :
fi
if ((0)); then
  :
else
  true
fi

debugoff


Reply via email to