Environment variable names used by the utilities in the Shell and Utilities volume of POSIX.1-2017 consist solely of uppercase letters, digits, and the ( â_â ) from the characters defined in Portable Character Set and do not begin with a digit. Other characters may be permitted by an implementation; applications shall tolerate the presence of such names. Uppercase and lowercase letters shall retain their unique identities and shall not be folded together. The name space of environment variable names containing lowercase letters is reserved for applications. Applications can define any environment variables with names from this name space without modifying the behavior of the standard utilities.
Other programming languages may use uppercase variables even when they are not environment variables, such as python and rust that use uppercase for constants.
What is missing from whonix
capitalize all environment variables
add to man page the use case of each environment variable
Thereâs a related developer helper script here. It does a Kicksecure and Whonix wide search and replace of any string anywhere in Whonix source code.
Whonix firewall scripts are using upper-case variables for normal variables.
Another reason of why their case needs to be distinct is to make the hierarchy obvious.
For example, if one variable is named gateway, its environment variable could still be named GATEWAY and it would be obvious their difference, because upper-case variables are variables exported to the environment.
export GATEWAY="sys-whonix-dev"
#!/bin/sh
# follow hierarchy:
# - command line
# - environment variable
# - default fallback value
gateway="${1:-"${GATEWAY:-"sys-whonix"}"}"
echo "${gateway}
this makes obvious that GATEWAY was exported to the environment and another variable can be used with the same name but lower case for defaults or assigned by other means.
The thing is, those variables are only used by firewall scripts.
Letâs take PATH for example, there is no problem in modifying PATH and adding ~/.local/bin to it by configuring it on the .bashrc, because PATH set in the .bashrc is user wide environment.
But the variables /etc/whonix_firewall.d are only for whonix firewall.
But in the end, you decide the approach but it has to be documented the standard to be followed, as it makes more clear what developers should use.
I generally agree with you. For the next release upgrade, we could move to the more conventional style.
To clarify, at this stage, we donât have any different opinions on this topic yet. Meaning, I am open to go with your suggestions. Just in case that previously came across differently.
So keep them lowercase?
I am not sure. In theory, whonix_firewall could be started from the command line with environment variables. Not sure that should be supported. An interesting use case would be firewall_mode.
Whatâs the convention for bash config snippets in /etc? /etc/default/grub uses uppercase variable names.
To improve my previous question: Lets say there was a script named debian-do-something by Debian (unspecific to Whonix) (asking general conventions here). How would global variables only valid in debian-do-something be stylized? Lowercase or uppercase?
The word âglobal variableâ might be quite confusing. Just script wide:
local variables (bash keyword local)
global variables (bash default)
I am not referring to Debian / Linux wide variables such as PATH, TERM etc.
For âglobalâ variables inside some standalone script. (grep -r bin/bash /usr/bin)
Which convention should be used? Probably not upper case unless that variable is documented as an environment variable?
sudo varname=content program
Then no -E / --keepenv required but indeed. Difficult to use and confusing. Thatâs more a thing for developers. Not something for user documentation.