ShellCheck代码检查工具(Linux方面)

Linux下ShellCheck脚本检查工具

安装工具流程

yum -y install epel-release
安装epel源
yum -y install ShellCheck
直接安装即可,注意大小写,小写的话会提示无此安装包

使用

[root@localhost ~]# shellcheck --help
unrecognized option `--help'

Usage: shellcheck [OPTIONS...] FILES...
  -e CODE1,CODE2..  --exclude=CODE1,CODE2..  exclude types of warnings
  -f FORMAT         --format=FORMAT          output format
  -s SHELLNAME      --shell=SHELLNAME        Specify dialect (bash,sh,ksh)
  -V                --version                Print version information
参考示例

这里提示问题所在位置及优化建议

[root@localhost ~]# shellcheck test.sh

In test.sh line 8:
mycat_2=$(netstat -atnp | grep "8066"|grep "java" | grep LISTEN | wc -l)
                                                    ^-- SC2126: Consider using grep -c instead of grep|wc.

参考文档
感谢这位大佬的博文
https://blog.csdn.net/hyb612/article/details/105459543?utm_medium=distribute.pc_feed.none-task-blog-alirecmd-4.nonecase&depth_1-utm_source=distribute.pc_feed.none-task-blog-alirecmd-4.nonecase&request_id=

你可能感兴趣的:(错查集锦,linux,shell,检查)