你最喜欢在Bash中处理错误的方法是什么?我在网上找到的处理错误的最好例子是由William Shotts,Jr在http://www.linuxcommand.org撰写.
他建议在Bash中使用以下函数进行错误处理:
#!/bin/bash
# A slicker error handling routine
# I put a variable in my scripts named PROGNAME which
# holds the name of the program being run. You can get this
# value from the first item on the command line ($0).
# Reference: This was copied from <http://www.linuxcommand.org/wss0150.php>
PROGNAME=$(basename $0)
function error_exit
{
# ----------------------------------------------------------------
# Function for exit due to fatal program error
# Accepts 1 argument:
# string containing descriptive error message …Run Code Online (Sandbox Code Playgroud)