Bash debugging experience bash is one of the most common shells in Unix/Linux operating systems. it is very flexible, working with awk and c ++ is exceptionally powerful. use a test script below www.2cto.com to demonstrate how to use bash to debug www.2cto. comtest. sh [plain] #! /Bin/bash... bash debugging experience bash is one of the most common shells in Unix/Linux operating systems. it is very flexible, working with awk and c ++ is exceptionally powerful. use a test script below www.2cto.com to demonstrate how to use bash to debug www.2cto.com test. sh [plain] #! /Bin/bash echo "---------------- begin -----------------" awk '{sum + = 1} END {print sum} 'test. sh MAX = 3 for (I = 0; I <MAX; I ++ )) do loaddate = 'date-d "-$ I day" + % Y-% m-% d' echo $ loaddate done echo "---------------- end ---------------" 1. use bash-xbash-x to print all the statements like: $ bash-x test. sh + echo ---------------- begin ------------------------------------- begin --------------- + awk '{sum + = 1} END {print s Um} 'test. sh14 + MAX = 3 + (I = 0) + (I <MAX )) + + date '-D-0 day' + % Y-% m-% d + loaddate = + echo 2013-03-052013-03-05 + (I ++ )) + (I <MAX )) + + date '-D-1 day' + % Y-% m-% d + loaddate = 2013-03-04 + echo 2013-03-042013-03-04 + (I ++ )) + (I <MAX )) + + date '-D-2 day' + % Y-% m-% d + loaddate = 2013-03-03 + echo 2013-03-032013-03-03 + (I ++ )) + (I <MAX) + echo ---------------- end ------------------- -------------- End ----------------- with the above annotations, bash-x can basically meet the daily 80% requirements. sometimes, our scripts are very complicated. if bash-x is used to obtain too many outputs, it is difficult to find the desired information and set can be used for local debugging, add "set-x" before the code to be debugged, and add "set + x" after the code to be debugged. like: modify test. sh :.... set-xawk '{sum + = 1} END {print sum}' test. shset + x ..... run: ---------------- begin ----------------- + awk '{sum + = 1} END {print sum} 'test. sh16 + set + x2013-03-052013-03-042013-03-03 ---------------- end ----------------- 3. use Bash debugging tool bashdb (Bash Debugger) bashdb is a GDB-like debugging tool, if you use GDB, you can use bashdb for basic accessibility. bashdb can run breakpoint settings, view variables, and other common debugging operations. bashdb needs to be installed and used separately as follows: $ bashdb -- debug test. sh bash debugger, bashdb, release 4.2-0.8 Copyright 2002,200 3, 2004,200 6, 2007,200 8, 2009,201 0, 2011 Rocky BernsteinThis is free software, covered by the GNU General Public License, and you arewelcome to change it and/or distribute copies of it under certain con Ditions. (/home/work/code/test. sh: 3): 3: echo "---------------- begin -----------------" bashdb <0> n # Next step ---------------- begin ----------------- (/home/work/code/test. sh: 5): 5: awk '{sum + = 1} END {print sum}' test. shbashdb <1> l # List up and down 10 lines of code 1 :#! /Bin/bash 2: 3: echo "---------------- begin -----------------" 4: 5: => awk '{sum + = 1} END {print sum} 'test. sh 6: 7: MAX = 3 8: for (I = 0; I <MAX; I ++) 9: do 10: loaddate = 'date-d "-$ I day" + % Y-% m-% d' bashdb <2> B 10 # set the Breakpoint 1 set in file/home /work/code/test. sh, line 10. bashdb <3> c # continue to run 14 Breakpoint 1 hit (1 times ). (/home/work/code/test. sh: 10): 10: loaddate = 'date-d "-$ I day" + % Y-% m-% d' bashdb <4> print $ I # print the variable value 0 14: echo "---------------- end -----------------"
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service