linux shell基本语法和调试技术

shell的语法跟c很多不一样,稍有不慎就各种问题,这里有个大神的调试技术总结,我也写了响应的代码验证。

 

原址:https://www.ibm.com/developerworks/cn/linux/l-cn-shell-debug/

执行以下命令的时候:export DEBUG=true

然后才有调试信息出来,否则就是只有错误提示信息。

调试手段:

  1. sh -x ./test.sh
  2. trap "command" signal
  3. tee /tmp/tmp.txt
  4. debug函数
  5. 增强调试:export PS4='+{$LINENO:${FUNCNAME[0]}} ';  sh -x ./test.sh;
#! /bin/bash


:<>/dev/null ;then
        echo "var1 is number"
else
        echo "var1 is not number"
fi



echo ""
for i in `seq 1 10`;do
        printf "%d " $i
done

echo
for((i=0;i<10;i++));do
        printf "%d " $i
done


temp=0
while true;do

                read -p "input number:(bigger than 10 to break)" temp
        echo $temp

        case $temp in
                        10)
                                        echo "break out"
                                        break
                                        ;;
                        *)
                                        echo "continue"
                                        ;;
        esac

done

echo "wc:"
wc -l <

 

你可能感兴趣的:(shell)