-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bash - Flag constants as read-only #17
Comments
Looks good to me! We'll incorporate this in our bash coding guidelines one way or another. Thanks. |
Looks like I was making an update at the same time you commented @faern , I added a section on how to declare local variables as read-only too. |
@faern Let me know if that's something you would be okay with or if you need to talk more internally before doing any change 👍 . |
Thank you. But I don't think we want too much churn in our bash scripts. We have plenty of scripts where we don't follow our own guidelines perfectly. So I expect it to be a can of worms. I want to open the lid to that can slowly. I think we first want to figure out exactly what our guidelines should say. There is a small problem with just doing what you wrote exactly. shellcheck prefers:
Because otherwise the exit code of the subshell is not handled properly. And I don't think we want to bloat all our scripts with extra lines just because of this. In the end, |
I totally understand 👍 . |
Global constants
In your coding guidelines:
coding-guidelines/bash.md
Lines 58 to 62 in 5c5931d
May I suggest to also declare these as readonly for more strictness?
The above example would become:
Your usual:
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
would become:
Local/scoped constants
On a very similar note, for variables scoped to their function with
local
:coding-guidelines/bash.md
Lines 94 to 104 in 5c5931d
For those that should be constants, additionally to having them written in uppercase you could also declare them as read-only with
local -r
:The text was updated successfully, but these errors were encountered: