Interview Prep/Shell Scripting/ShellCheck, debugging, testing, portability and security

What is `shfmt` and why use it alongside ShellCheck?

BeginnerConceptShellCheck, debugging, testing, portability and security
Answer

shfmt formats shell code consistently (indentation, spacing, case layout), like gofmt for shell. ShellCheck finds bugs; shfmt ends style debates in code review.

shfmt -d -i 2 -ci scripts/     # show diff: 2-space indent, indent case branches
shfmt -w -i 2 -ci scripts/     # rewrite in place

Run it in CI with -d so unformatted code fails the build.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on ShellCheck, debugging, testing, portability and security