Bash Code Style
Generally follows https://google.github.io/styleguide/shellguide.html
And the following rules have higher priority.
Editor Settings
- Your editor must be able to recognize the
.editorconfigfile in project. - Shellcheck must be installed, and your editor must support it.
File naming
- All filenames must match the regex
[-_a-z0-9], except other particular files (likeDockerfile). - All script filenames must end with
.bash.
File Header
- For executable files, put
#!/usr/bin/env bashat the top of file. - For
.batsfiles, put#!/usr/bin/env batsat the top of file. - No shebang for non-executable files.
Test
- Use bats for unit testing.
Rules
- No
functionkey. Function declarationfunc() {...}is preferred overfunction func() {...}.