Hello
A main bash script call other bash scripts that may call other bash scripts.
Each bash script contains :
set -E # ~ trap on ERR is inherited
set -T # ~ trap on DEBUG and RETURN are inherited
set -o errexit # ~ set -e
set -o nounset # ~ set -u
set -o pipefail
shopt -s inherit_errexit # Enable (set) each optname.
During startup, the main script source a script that contains numerous small bash functions.
A trap error function is installed and show the following information :
The ‘last command’ call a function of mine that may return the name of the suse install repo.
This function search for 'hd:' or ‘cd:/?devices=’ to get something like ‘openSUSE-Leap-15.5-1’
How to complete the output of my trap function with the name of the function that raise the error, and if possible the line number.
Bash currently doesn’t have a native “Try - Catch” functionality.
But, it does have a builtin “trap” function – the “bashbuiltins” man page explains all the details you need.
You can also define a custom error-handling function which the “trap” function calls when it executes – for example:
#!/bin/bash
handle_error() {
echo "Error on line $1"
exit 1
}
trap 'handle_error $LINENO' ERR
I am sorry but you don’t read carefully my question.
1°)During startup, the main script source a script that contains numerous small bash functions.
2°)Bash initializsation
set -E # ~ trap on ERR is inherited
set -T # ~ trap on DEBUG and RETURN are inherited
set -o errexit # ~ set -e
set -o nounset # ~ set -u
set -o pipefail
shopt -s inherit_errexit # Enable (set) each optname.
3°)A trap error function is installed and show the following information …
And the question is specifically on this subject : Nothing in the trap output give information on the function that raise the trap.
How to complete the output of my trap function with the name of the function that raise the error, and if possible the line number.