ShinobuAmasaki / fpm-completions

Command-line completion functions for the Fortran Package Manager.
MIT License
8 stars 2 forks source link

bash version, suggestions by shellcheck #3

Closed nbehrnd closed 8 months ago

nbehrnd commented 9 months ago

A copy-paste of file fpm.bash into shellcheck yields a couple of suggestions how the script can be improved further. Possibly, an additional leading line of #!/usr/bin/env bash may be worth to consider, too.

Typically I check shell scripts for the bash equally with checkbashisms. Speaking for Linux Debian, it is provided by devscripts equally available under this name for other OSes. I'm not aware if there is an interactive web site to run the tests (similar to shellcheck) without a local installation. And checkbashisms equally provides some suggestions to improve the script.

ShinobuAmasaki commented 9 months ago

Thank you for introducing useful tools.

Regarding your suggestion, when referring to the purpose of the shebang, it is intended to specify the interpreter to the operating system by placing a special line at the beginning of an executable script file. In this case, since fpm.bash is NOT intended to be an executable file itself, but rather to be sourced or loaded by the bash shell, the #!/usr/bin/env bash is not necessary and, in fact, should be omitted.

In practice, many script in the /usr/share/bash-completion/completions directory (or similar directory depending on your distribution) that are part of the bash-completion package do not have shebang line (although there are exceptions). This practice aligns with the property of scripts meant to be sourced or loaded rather than executed directly.

nbehrnd commented 8 months ago

Thank you for indicating the difference between .sh as source vs .sh of an executable. Hence, I drop this part of the suggest.

ShinobuAmasaki commented 8 months ago

Thank you for your suggestions. The code improvements made by shellcheck were incorporated into my workflow and reflected in the v0.2 release.

Thanks.