Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个非常高级且复杂的脚本,我基本上需要使用 set -e on 进行调试(因为我希望它在我制定逻辑时不要在循环中运行昂贵的操作),但它变得越来越困难(甚至使用 set -x) 来确定脚本由于意外结果而退出的确切位置。
我有大约 3 个脚本以各种方式相互调用(结合 inotifywatch),所以你可以看到它是如何变得有点毛茸茸的。
我正在寻找类似“Script x.sh exited at line 4”之类的东西,而不是无信息的[exited]
[exited]
Read man bash about trap, BASH_LINENO and FUNCNAME.
man bash
trap
BASH_LINENO
FUNCNAME
You should be able to use trap to call an own function in case of an error. In this function you can use the given arrays to get an idea what went wrong.