
Shellcheck 是一个静态 Bash 语法检查工具,它可以在多种场景下使用,包括在线使用、命令行检查、编辑器配置。
当你在 Linux / Unix 平台下编写 Bash Shell 编译大量代码的时候,常常会花费大量的时间,然而这时你可以通过 Shellcheck 提前知道你所写脚本的语法问题,同样也会给出你相关纠错提示。

除了在线使用之外,还可以通过命令行进行检查,支持基于 Debian、Arch Linux、EPEL、Fedora、FreeBSD、MacOS、OpenSUSE、Windows 等多个操作系统上进行安装检查;
对于 Shellcheck 命令行的安装方式,可以参考 Shellcheck 的 GitHub 库。
脚本案例:
#!/bin/bash
DIRPATH='/tmp/jstack'
CURRENT_TIME=$(date +'%F'-'%H:%M:%S')
if [ ! -d "$DIRPATH" ];then
mkdir "$DIRPATH"
else
rm -rf "$DIRPATH"/*
fi
cd "$DIRPATH"
while true
do
sleep 3600
# 这里需要将inceptor改后自己的java进程名称
pid=$(ps -ef | grep 'inceptor' | grep -v grep | awk '{print $2}')
jstack $pid >> "jstack_${CURRENT_TIME}"
dir_count=$(ls | wc -l)
if [ "$dir_count" -gt 10 ];then
rm -f $(ls -tr | head -1)
fi
done
Shellcheck 检查输出结果:
$ shellcheck myscript
Line 10:
rm -rf "$DIRPATH"/*
^-- SC2115 (warning): Use "${var:?}" to ensure this never expands to /* .
Line 13:
cd "$DIRPATH"
^-- SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
Did you mean: (apply this, apply all SC2164)
cd "$DIRPATH" || exit
Line 19:
pid=$(ps -ef | grep 'inceptor' | grep -v grep | awk '{print $2}')
^-- SC2009 (info): Consider using pgrep instead of grepping ps output.
Line 20:
jstack $pid >> "jstack_${CURRENT_TIME}"
^-- SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean: (apply this, apply all SC2086)
jstack "$pid" >> "jstack_${CURRENT_TIME}"
Line 21:
dir_count=$(ls | wc -l)
^-- SC2012 (info): Use find instead of ls to better handle non-alphanumeric filenames.
Line 23:
rm -f $(ls -tr | head -1)
^-- SC2046 (warning): Quote this to prevent word splitting.
^-- SC2012 (info): Use find instead of ls to better handle non-alphanumeric filenames.
$
Shellcheck 在线使用地址:
https://www.shellcheck.net/#
Shellcheck GitHub 地址:
https://github.com/koalaman/shellcheck
数据统计
数据评估
关于(ShellCheck – shell script analysis tool)特别声明
本站商娱网提供的ShellCheck – shell script analysis tool都来源于网络,不保证外部链接的准确性和完整性,同时,对于该外部链接的指向,不由商娱网实际控制,在2022-01-07 13:58收录和巡查时,该网页上的内容,都属于合规合法,后期网页的内容如出现违规,可以直接联系网站管理员进行删除,商娱网不承担任何责任。
相关导航

一个在线智能抠图工具,把图...

PDF转Word转换器
使用我们的免费在线PDF转Word转换器轻松地将PDF文件转换为可编辑的Word文档。高质量、安全且高效的转换。

极速图片压缩器
极速图片压缩器,一款压缩速度极快的图片压缩软件。

发音纠正器
发音纠正器 纠正你的英文发音

SHELLPUB.COM在线查杀
shellpub.com专注webshell查杀,免费查杀软件,web查杀,webshell在线查杀,在线检测网站后门,速度快,误报低,准确度高。

Telegram Web
Telegram Web

PDDON
PDDON是一款完全免费的轻量级专业在线画图和低代码工具。目前已具备绘制流程图、UML图、架构图、类图、序列图、部署图、活动图、状态图、用例图、思维导图、ER图等等设计图。PDDON is a completely free online lightweight professional drawing and low code tool. At present, it has the ability to draw flow chart, UML diagram, architecture diagram, class diagram, sequence diagram, deployment diagram, activity diagram, state diagram, use case diagram, mind map, ER diagram and other design diagrams.

发现 AppStore 图标
发现 AppStore 图标 是一个快速搜索并下载你喜欢的应用图标。
暂无评论...