Shell Script Debugging Tips

Source: Internet
Author: User
Tags echo command

0. Standard format for professional scripting

Function 1 function 2main function main $*


1. Use the Dos2unix command to convert scripts developed under Windows

Dos2unix is not installed by default and can be installed in Yum

# Dos2unix web_jk.shdos2unix:converting file web_jk.sh to UNIX format ...


2. Debug with echo command


3. Debugging with bash command parameters

# sh [-NVX] scripts.sh-n does not execute the script, only queries the script syntax for problems, and gives error hints. -V When executing the script, output the contents of the script to the screen and execute the script, if there is an error, it will also give an error. -X * * * will execute the script content and output display to the screen, for debugging super useful parameters!


4. Debug part of the script content with set command parameters

-N Read command but do not execute-V show all rows read-X * * Displays all commands and their arguments


Write in the script:

Set-xdiff/tmp/a.txt.ori/tmp/a.txtset +x


Tips:

The debug function is turned on by the Set-x command, while the debug function is turned off via set +x


5. Habit

The most critical is the proficiency of grammar, coding habits, programming ideas, to kill the error in the bud, reduce the burden of debugging, improve efficiency.


This article is from the "Chen was 007" blog, please be sure to keep this source http://chenfage.blog.51cto.com/8804946/1895982

Shell Script Debugging Tips

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.