标签:函数 成功 执行 linu exec bash rap bug 状态码
linux 使用trap命令进行调试
Shell脚本在搪行时,会产生三个所谓的伪信号。
三种伪信号如下:
信号名称 产生条件
EXIT 从函数中退出,或者整个脚本执行完毕
ERR 当一条命令返回非零状态码,即命令执行不成功
DEBUG 脚本中的每一条命令执行之前
vi trapdebug.sh
#!/bin/bash
trap ‘echo "before execute line:$LINENO, a=$a, b=$b, c=$c"‘ DEBUG #trap命令捕捉DEBUG
a=0
b=2
c=100
while :
do
if ((a >= 10))
then
break
fi
let "a=a+2" #a、b、c值不断变化
let "b=b*2"
let "c=c-10"
done
./trapdebug.sh
before execute line:4, a=, b=, c=
before execute line:5, a=0, b=, c=
before execute line:6, a=0, b=2, c=
before execute line:8, a=0, b=2, c=100
before execute line:10, a=0, b=2, c=100
before execute line:14, a=0, b=2, c=100
before execute line:15, a=2, b=2, c=100
before execute line:16, a=2, b=4, c=100
before execute line:8, a=2, b=4, c=90
before execute line:10, a=2, b=4, c=90
before execute line:14, a=2, b=4, c=90
before execute line:15, a=4, b=4, c=90
before execute line:16, a=4, b=8, c=90
before execute line:8, a=4, b=8, c=80
before execute line:10, a=4, b=8, c=80
before execute line:14, a=4, b=8, c=80
before execute line:15, a=6, b=8, c=80
before execute line:16, a=6, b=16, c=80
before execute line:8, a=6, b=16, c=70
before execute line:10, a=6, b=16, c=70
before execute line:14, a=6, b=16, c=70
before execute line:15, a=8, b=16, c=70
before execute line:16, a=8, b=32, c=70
before execute line:8, a=8, b=32, c=60
before execute line:10, a=8, b=32, c=60
before execute line:14, a=8, b=32, c=60
before execute line:15, a=10, b=32, c=60
before execute line:16, a=10, b=64, c=60
before execute line:8, a=10, b=64, c=50
before execute line:10, a=10, b=64, c=50
before execute line:12, a=10, b=64, c=50
标签:函数 成功 执行 linu exec bash rap bug 状态码
原文地址:https://www.cnblogs.com/zhudaheng123/p/14654667.html