set -xv

1.set -x 或set xtrace

会显示+以及脚本中的内容(执行的部分,没执行的不显示)

set -xv(脚本中所有的内容都显示,包括没执行的部分)

2.debug=3   //多层级调试

test $debug -gt 0 && echo "a"
test $debug -gt 1 && echo "b"
test $debug -gt 2 && echo "c"

3.函数

func(){
echo "my func"
}
echo "begin"
func  //注意调用函数的时候不能加括号
echo "end"

4. 函数返回值以及read函数(相当于scanf)

func1(){
echo "enter a"     //
read a
echo "enter b"
read b
echo "a=$a b=$b"
return $(($a+$b))
}
func1
echo "a+b=$?!"

原文地址:https://www.cnblogs.com/xpylovely/p/11152757.html