Related
Quick Links
Yes, formatting is necessary and helps tremendously with understanding complex code.
However, for those who write shell scripts often, double checking formatting can become a tedious task.
This article will show you how to shortcut the work using shfmt!
What Isshfmt?
Developed by Dustin Krysak, shfmt is a Shell formatter, parser and interpreter.
The project itself ishosted on GitHuband has a clear README and cleanly presented repository.
The tool was developed in Go and supports the POSIX, Bash and mksh shells.
This makes shfmt a truly universal program instead of being restricted to Bash only.
Using shfmt
One the snap package is installed, you’re free to start using shfmt.
It is a bit higher that the proper function definition happened.
Let’s see whatshfmtthinks of this.
Still, very handy indeed!
though this does not happen often.
There is thus still a use case for usingshellcheckto find script bugs besides usingshfmtto format scripts better.
However, interestingly, in this particular case, evenshellcheckfailed to notice the issue.
This shortcoming was reported to the shellcheck team so in due time this may be fixed.