Skip to content

Comments

Introduced draft of SSG Bash scripting guidelines.#2633

Merged
mpreisler merged 1 commit intoComplianceAsCode:masterfrom
matejak:bash-guidelines
Feb 28, 2018
Merged

Introduced draft of SSG Bash scripting guidelines.#2633
mpreisler merged 1 commit intoComplianceAsCode:masterfrom
matejak:bash-guidelines

Conversation

@matejak
Copy link
Member

@matejak matejak commented Feb 28, 2018

As @OnceUponALoop in #2617 noticed, it is not clear what style and approach to prefer when contributing to Bash remediations.
I have went to the existing remediations in the shared/fixes/bash folder and observed the prevalent existing style. I have found out two points which I believe that are not controversial at all:

  • most scripts use tabs for indentation, so let's use tabs.
  • usage of sed greatly surpasses awk, so let's encourage sed.

Next, I propose these:

  • Use the die function idiom to handle possible errors (I have defined it and checked that it can be actually used).
  • Run shellcheck over the snippet and try to fix all warnings.
  • Avoid double negatives s.a. if ! [ $x != 1 ]; then ...

Finally, some points may be controversial:

  • I have slightly encouraged usage of compound statements. I think that if they are used in moderation, they can make the code much shorter, without obscuring anything.
  • I have suggested to write scripts in a way that they work if invoked in the "strict mode" e.g. by running them using bash -e or by writing set -e to the top of the script. This imposes greater requirements on error handling inside the script and therefore increases its robustness.

@matejak matejak added this to the 0.1.38 milestone Feb 28, 2018
@matejak matejak added the enhancement General enhancements to the project. label Feb 28, 2018
@mpreisler mpreisler self-assigned this Feb 28, 2018
@mpreisler
Copy link
Member

ACK, great stuff!

@mpreisler mpreisler merged commit 8eb015a into ComplianceAsCode:master Feb 28, 2018
@shawndwells
Copy link
Member

Agreed, thank you for doing this @matejak!

@matejak matejak deleted the bash-guidelines branch July 19, 2018 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement General enhancements to the project.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants