linux - 在 Bash 脚本中设置 -e : discovering failure location?

标签 linux bash error-handling

众所周知,我们应该使用set -e来制作Bash脚本more robust .但是,启用此功能后,如果脚本确实 失败了,是否有任何方法可以让 Bash 报告脚本的哪一行失败?目前,我必须使用大量 echo 命令重新运行脚本。

最佳答案

我知道使用行号进行调试的最佳选择是自定义 set -x 打印的“+”前缀以包含 $LINENO

例如在脚本的顶部:

PS4='($LINENO)+ '
set -x

(不完全是你要求的,但它很方便!)

关于linux - 在 Bash 脚本中设置 -e : discovering failure location?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8202054/

相关文章:

bash - 如何通过在 ubuntu 中包含 "cd"命令来运行 shell 脚本?

php - 在 Woocommerce 中更改错误通知文本并针对此错误采取措施

android - 在 MVVM 架构中处理来自 api 端点的错误的最佳实践是什么?

python - 在 Python 中启动进程并检索其窗口 ID

git - 在 Bash 脚本中为 Git 提供密码

linux - 如何修复 "no symbol version for module_layout"?

c++ - 陷阱无法捕获 SIGSEGV

mysql - 如何解决mysql_error()?

linux - 无法获取 'at' 在 linux 下运行脚本

linux - 如何对多个文件运行拼写检查并在 shell 脚本中显示任何不正确的单词?