Shell Script debugging

Source: Internet
Author: User

Bash is the default scripting language in a Linux system, and since it is a programming language, debugging of scripts is essential. Here's a simple debugging approach to bash:

1 using Bash's parameter-X, such as

Bash-x a.sh

+ for A in ' bafa{1..4} '

+ ID BAFA1

+ Echo ' bafa1 is exits '

BAFA1 is exits

+ for A in ' bafa{1..4} '

+ ID BAFA2

+ Echo ' bafa2 is exits ' #+ means print out each line of script

BAFA2 is exits #打印出脚本执行的结果

+ for A in ' bafa{1..4} '

+ ID Bafa3

+ Echo ' bafa3 is exits '

Bafa3 is exits

+ for A in ' bafa{1..4} '

+ ID BAFA4

+ Echo ' bafa4 is exits '

BAFA4 is exits

+ + Date ' +%f%T ' #++ represents the call

+ echo ' 2017-03-27 14:03:34 '

2017-03-27 14:03:34


2 If the script is too long, use set-x to open the script for trace debugging

such as: Vim a.sh

#!/bin/bash

For a in bafa{1..4};d o

If ID $a &>/dev/null;then

echo "$a is exits"

Else

Useradd $a && echo "$a" | passwd--stdin $a &>/dev/null

echo "$a is create OK"

Fi

Done

Set-x

echo "$ (date +"%F%T ")"

Set +x


Increased execution permissions: chmod +x a.sh


./a.sh

BAFA1 is exits

BAFA2 is exits

Bafa3 is exits

BAFA4 is exits

+ + Date ' +%f%T '

+ echo ' 2017-03-27 14:17:27 '

2017-03-27 14:17:27

+ Set +x


This article from "10,000 years too long, seize" blog, please be sure to keep this source http://zengwj1949.blog.51cto.com/10747365/1910716

Shell 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.