Shell Script Raiders (reading notes)--1.10 debug scripts

Source: Internet
Author: User

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

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.