Hello.
I am testing a trap function which print the error , which line , and where.
I am using a piece of code found here : call stack in trap
I made a program (program 1) to test the code.
But the program stop at line 114 when
((--i))
reach 0
The output is :
triger an error -->
ls: cannot access '': No such file or directory
Function call stack ( command.function() ) ...
Knowing the index value at startup, I made a modified program that mimic program 1
The output is :
triger an error -->
ls: cannot access '': No such file or directory
i : 3
Function call stack ( command.function() ) ...
/home/user_install_vb/test_004-d.sh.main()
/home/user_install_vb/test_004-d.sh._READ_NEW_USER_CONFIG_FILES_()
/home/user_install_vb/test_004-d.sh.callStack()
Because the status of (( 0 )) is non-zero and you told shell to immediately exit in this case. I presume, bash cannot recursively call ERR function if error happened inside this function.
Thank you very much.
But I have another problem with another arithmetic calculation in the same program with the same trap function.
I call a function ‘foo’ from a find search .
A global variable count files and is initialized to 0 at beginning of the main program.
The function foo increment the number of passed files just before returning.
Incrementing the counter ‘(( COUNT++ ))’ trigger the trap error.
But when the function ‘callStack’ is run, the index is initialized to a value (here “3”).
The first decrement line 107 (–i)) give ((2)) which is non-zero also.
What is the difference