bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

issue with debug trap


From: Giacomo Comes
Subject: issue with debug trap
Date: Fri, 15 Dec 2023 17:21:23 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

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

[Prev in Thread] Current Thread [Next in Thread]