shell (fourteen) shell debugging

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/wzj_110/article/details/100543462

A shell Notes

(1) at the beginning of the script file version copyright information

# 提示:可配置vim编辑文件时自动加上以上信息,方法是修改~/.vimrc配置文件

(2) emphasis on writing habits , develop norms and develop systems to minimize the difficulty and the number of scripts modal, improve development efficiency

# 成对的书写,先把框架写出来
	
{}、[]、''、``、""

(3) shell of grammar to be familiar with in order to better script debugging

# []中括号两端要有空格,书写时即可留出空格[    ],然后再退格书写内容

# 流程控制语句一次性书写完,再添加内容

# 通过缩进让代码易读;(即该有空格的地方就要有空格)

(4) To clear script ideas

    1)思考开发的框架

    2)尽量模块化

    3)复杂的脚本分块化

# main主函数、main$*

Two  shell script debugging techniques

(1) dos2unix treated

# 只要不是在Linux下:从Windows拿过来或者从网上下载

# 默认没有安装

yum install dos2unix.x86_64

(2) with echo debugging

#  场景:脚本比较长,但是语法没有问题,是逻辑错误!

(3) shell carrying the command line parameters

-n 	只读取shell脚本,但不实际执行 	        仅仅测试shell脚本是否存在语法错误
-x 	进入跟踪方式,显示所执行的每一条命令 	使shell在执行脚本的过程中把它实际执行的每一个命令行显示出来
-v      在执行脚本之前,先显示整个脚本的内容然后执行脚本,如果有错误会给出错误提示!

# -x常用

# sex -x  -->缩小调试的范围

ShellCheck use

# 要检查现有项目的所有的脚本,

find your_project_folder -name "*.sh" | xargs -i shellcheck {} 

# 即可实现批量检查

# epel安装

yum install ShellCheck.x86_64 

# 语法检查相应的提示

shellcheck  script

Related reference 1

Related reference 2

Guess you like

Origin blog.csdn.net/wzj_110/article/details/100543462