在bash
脚本中,如何通过某种自定义消息向(bash脚本调用人员)用户发信号通知已触发过早退出错误?
我想发送一个明确的失败消息,例如
! ** !
Oops, something went wrong.
This script did NOT successfully finish.
! ** !
以便用户了解脚本未成功完成。 (有时这一点还不清楚,并且用户错误地认为脚本已成功完成。)
最佳答案
回答我的评论,这里是扩展(Gilles Quenot's answer)如何在退出脚本时如何保留错误返回代码:
#!/usr/bin/env bash
trap 'rc=$?; cat<<EOF >&2
! ** !
Oops, something went wrong.
This script did NOT successfully finish.
! ** !
EOF
exit $rc' ERR
failme ()
{
return $1
}
failme 10
关于bash - 在bash脚本: how to signal to the (human) user that an error triggered a premature exit?中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62504165/