Using Sh-x or this bash-x, you can debug a script that outputs and outputs a state for each row while debugging, and It also shows the order in which the commands in the script are executed . You can also use set in the script to set the debug area.
For example, debug the above time_calculate.sh script.
[Email protected] tmp]# sh-x time_calculate.sh
+ + Date +%n
+ start_time=086352877
+ Find/-type f-name ' *.db '
+ + Date +%n
+ end_time=352144614
+ + echo ' scale=6;352144614/10^6 '
+ + BC
+ diff_time=352.144614
+ Echo 352.144614
352.144614
If there is a place to perform the error will be displayed.
For example, modify the time_calculate.sh script, modify the calculated section to an incorrect expression, and set up this section of debugging.
[email protected] tmp]# cat time_calculate.sh
#!/bin/bash
# calculated in microseconds
start_time=$ (Date +%n)
Find/-type F-name "*.db" &>/dev/null
end_time=$ (Date +%n)
#diff_time =$ (echo "scale=6;$ (end_time-strat_time)/10^6" | BC)
set-x Start debugging from here
Diff_time=$ (echo "scale=6; $ (end_time-strat_time)/10^6 "| BC) ? Make a change here error
Echo $diff _time
set +x ? End Debugging here
Execute script:
[Email protected] tmp]# sh time_calculate.sh
+ + BC
+ + End_time-strat_time
time_calculate.sh:line 8:end_time-strat_time:command not found ? The front no plus + is the wrong place.
+ + echo ' scale=6;/10^6 '
(standard_in) 1:syntax error
+ diff_time=
+ Echo
+ Set +x
Because/bin/bash can also perform-X debugging, #!/bin/bash Plus-X can always be debugged directly at the beginning of the script. That is #!/bin/bash-x.
Shell Script Raiders (reading notes)--1.10 debug scripts