-
Notifications
You must be signed in to change notification settings - Fork 1
Description
We need to normalize all of our bash scripts. This includes:
- Normalization and inclusion of correct shabangs in each script
- Ensuring all file extensions are the same (so in files with a
bashshabang, the file extension for these should be.bash). This can cause some messing with how the git history is tracked, so file extensions are not super high prority but we still need to hit this - Correct usage of
returnandexitwithin our bash commands. - Utilization of shellformat and shell check. The specific usage is below:
shellcheck --enable=require-variable-braces,quote-safe-variables,add-default-case <fileToLintHere>shfmt -i 4 -ci -fn <fileToFormatHere>
Bug Description:
A recent bug caused by this was the gems/tests/run_tests.sh script having a #!/bin/sh shabang which caused it to not have the bash source command available to it. Furthermore, inconsistencies increases brain usage which is bad and makes scripts that would grab all specific files etc. to run tools on them more difficult.
Additional context
Think of different shells as kinda like different programming langauges. They are not all interchangeable, so we gotta keep that in mind. If we just stick to bash shells that use the baseline commands/progs we should be good. Getting a collection of all our scripts without shabangs would be good for someones first issue, actually changing them and ensuring the shabangs are correct is dependent on the devs skill level
Information regarding shabangs:
- https://stackoverflow.com/questions/16365130/what-is-the-difference-between-usr-bin-env-bash-and-usr-bin-bash
- https://stackoverflow.com/questions/21612980/why-is-usr-bin-env-bash-superior-to-bin-bash
- https://stackoverflow.com/questions/10376206/what-is-the-preferred-bash-shebang
Information Regarding exit vs. return
- Basically, exit exits the script while return returns a code. From my understanding, we should use
returnin our functions, and ngl we can useexitin our functions if the script is supposed to exit if a function fails but this pattern isnt very common. So let's just go forreturnon all our functions while usingexitto react to a failed functions return value - https://stackoverflow.com/questions/4419952/difference-between-return-and-exit-in-bash-functions
- https://tldp.org/LDP/abs/html/exit-status.html
- https://www.baeldung.com/linux/return-vs-exit