Il giorno ven 13 ago 2021 alle ore 15:08 Roberto A. Foglietta < [email protected]> ha scritto:
> Hi all, > > the patch attached to this mail add the trap ERR feature. > This second patch goes after the first one: - add a bugfix to the first patch - enable global $LINENO At the moment when $LINENO is printed by a function the number displayed is the lines from the start of the function. Unfortunately, this information is useless because we do not have $FUNCNAME. Even if we have $FUNCNAME having always an absolute $LINENO will be more easier. In fact this will be the quickest way to reach the break point - vi script.sh :$n The two patches goes together because having the $LINENO without the ability to use in an error trap is not very useful. Moreover, I add in attachment a script for testing. Please let me know what you think, -R
busybox-1.33.1-trap-ERR-fix-global-LINENO.patch
Description: Binary data
#!/bin/ash
function realexit() {
trap - EXIT
exit $1
}
function perr() {
echo -e "\e[1;31m$@\e[0m"
}
function onerror() {
rc=$?
# echo
perr "ERROR: $(basename $0) failed${2+ in $2()} at line $1, rc: $rc"
echo "onerror() at line $LINENO == 16"
# echo
# realexit $rc
}
function mytest() {
echo "hello at line $LINENO == 22"
false
}
trap 'onerror $LINENO $FUNCNAME' ERR
trap 'echo exit at line $LINENO == 34 with pippo but not pluto' EXIT
echo "ciao! at line $LINENO == 29"
mytest
echo "mytest should have failed at line 23"
echo "pippo"
set -e
false
echo "pluto at line 38"
_______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
