fix(hooks): make env var regex portable

Adjust the regex used to detect ${ENV_VAR} patterns in
hooks/_common.sh to avoid Bash-incompatible constructs and to be
compatible with macOS/BSD regex behavior.

- Remove unnecessary leading/trailing '.*' since =~ matches substrings.
- Allow lowercase letters in subsequent identifier characters
  ([A-Za-z0-9_]) so variable names with lowercase chars are detected.
- Keep first-char restriction to uppercase or underscore to match
  existing extraction logic.

Signed-off-by: Michael Rosenfeld <mrosenfe@sheetz.com>
This commit is contained in:
Michael Rosenfeld 2026-06-12 15:24:20 -04:00
commit caab3b8701
No known key found for this signature in database
GPG key ID: 3490074540F4F2C8

View file

@ -112,7 +112,7 @@ function common::parse_and_export_env_vars {
while true; do
# Check if at least 1 env var exists in `$arg`
# shellcheck disable=SC2016 # '${' should not be expanded
if [[ "$arg" =~ .*'${'[A-Z_][A-Z0-9_]*'}'.* ]]; then
if [[ "$arg" =~ '${'[A-Z_][A-Za-z0-9_]*'}' ]]; then
# Get `ENV_VAR` from `.*${ENV_VAR}.*`
local env_var_name=${arg#*$\{}
env_var_name=${env_var_name%%\}*}