Shell Scripting Learning Summary 11--script debugging

Source: Internet
Author: User

Parameters:

-N does not execute script, only checks syntax for errors

-V Output the script contents to the screen and execute the script

-X executes the script and outputs the content to the screen

-N


-V

Ten module () {  eval '/usr/bin/modulecmd bash $*'}#/bin/bashif [$15  ];then   "Yes"or "else"     No " Fiyes

-X

[[Email protected] sbin]# SH-'['5']'   2operator  expected+ echo Nono

Expand:

Use PS4 to make debugging output line numbers

[[email protected] sbin]# echo $PS 4+[[email protected] sbin]# export PS4='+{$LINENO}  '[[email protected] sbin]# Sh-x debug.sh 4
+{2} ' [' 4-gt 5 '] '
+{5}echo No
No

Use set to narrow the scope of debugging

Set-x Turn on debug function

Set +x turn off the debug function

[email protected] sbin]# Cat demo.sh #/bin/bash./etc/init.d/functionsSet-Xread-P"pleas input your anwser[yes/no]:" anSet+xif[[$an =Yes]] Then action"The answer is true"/bin/trueElseAction"Then answer is False"/bin/falsefi[[email protected] sbin]# sh demo.sh+{4}read-p'pleas input your anwser[yes/no]:'Anpleas Input your anwser[yes/No]: Yes+{5}Set+XThe Answer is true[OK]

Shell Scripting Learning Summary 11--script debugging

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.