歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> Shell 調試

Shell 調試

日期:2017/3/1 12:24:36   编辑:SHELL編程
一、簡介 本文全面系統地介紹了shell腳本調試技術,包括使用echo, tee, trap等命令輸出關鍵信息,跟蹤變量的值,在腳本中植入調試鉤子,使用“-n”選項進行shell腳本的語法檢查, 使用“-x”選項實現shell腳本逐條語句的跟蹤,巧妙地利用shell的內置變量增強“-x”選項的輸出信息等。 二、shell調試選項 1)只讀取shell腳本,不實際執行,用於檢測shell腳本是否存在語法錯誤 -n 2)使shell解釋器從一個字符串中讀取並執行shell指令,用於臨時測試小段腳本 -c "string" 3)進入跟蹤方式,使shell在執行腳本的過程中把它實際執行的每一個命令行顯示出來,並且在行首顯示一個"+"號 -x 示例:
$ sh –x exp2.sh
+ trap 'echo "before execute line:$LINENO, a=$a,b=$b,c=$c"' DEBUG
++ echo 'before execute line:3, a=,b=,c='
before execute line:3, a=,b=,c=
+ a=1
++ echo 'before execute line:4, a=1,b=,c='
before execute line:4, a=1,b=,c=
+ '[' 1 -eq 1 ']'
++ echo 'before execute line:6, a=1,b=,c='
before execute line:6, a=1,b=,c=
+ b=2
++ echo 'before execute line:10, a=1,b=2,c='
before execute line:10, a=1,b=2,c=
+ c=3
++ echo 'before execute line:11, a=1,b=2,c=3'
before execute line:11, a=1,b=2,c=3
+ echo end
end
三、shell調試工具:bashdb http://bashdb.sourceforge.net/
Copyright © Linux教程網 All Rights Reserved