#!/bin/sh
HOME_DIR=/home/xxx
CROSSTOOL_INSTALL_DIR=${HOME_DIR}/crosstool_install# 必须要设置,可以根据FUNCNAME查到函数调用栈
# Inherit the fault handler in subshells and functionsset -E#设置捕捉信号,ERR 当一条命令返回非零状态时(代表命令执行不成功) trap die ERR#trap 'echo "fun: ${FUNCNAME[0]} " ' DEBUG
#trap 'echo "LINENO: ${LINENO} " ' DEBUGdie(){ local ret=$? local depth #echo " Error: [FILE: $0 LINE: $1] exited with status $ret " #打印调用函数栈 #echo " backtrace: ${FUNCNAME[@]} " for((depth=1; ${BASH_LINENO[$((${depth}-1))]}>0; depth++)); do #file="${BASH_SOURCE[${depth}]#./}" file="${BASH_SOURCE[${depth}]}" func="${FUNCNAME[${depth}]}" line="${BASH_LINENO[${depth}-1]:-?}" echo "Backtrace: ${file}[${func}() <${line}>]" done #死循环等待ctrl + c while true do sleep 1 done}CREATE_MAKE_DIR()
{ #echo "test fun: ${FUNCNAME[@]} " if [[ -d ${CROSSTOOL_INSTALL_DIR} ]] then echo -e "${CROSSTOOL_INSTALL_DIR} is exit,no create" return 0 fi #出错位置 return 1;}#创建编译目录
CREATE_MAKE_DIR验证打印:
打印错误位置