Reviewer · Code Style
Shell variable scoping and substitution
In shell scripts, always declare function-scoped variables with the `local` keyword to prevent accidentally leaking or overwriting global state. Avoid introducing an intermediate variable just to hold a single-use positional parameter—reference `$1`, `$2`, etc. directly unless a named variable materially improves clarity. When capturing command output,...
In shell scripts, always declare function-scoped variables with the local keyword to prevent accidentally leaking or overwriting global state. Avoid introducing an intermediate variable just to hold a single-use positional parameter—reference $1, $2, etc. directly unless a named variable materially improves clarity. When capturing command output, prefer $(...) command substitution over backticks, since it is more readable and composable (nests cleanly). For example:
```bash
Avoid
map_goos_to_uname() { GOOS=$1 case “$GOOS” in … esac }
get_release_entry() {
GOOS=$1
GOARCH=$2
s3Os=map_goos_to_uname $GOOS
s3Arch=map_goarch_to_uname $GOARCH
…
}
Prefer
map_goos_to_uname() { case “$1” in … esac }
get_release_entry() { local GOOS=”$1” local GOARCH=”$2” local s3Os=”$(map_goos_to_uname “$GOOS”)” local s3Arch=”$(map_goarch_to_uname “$GOARCH”)” … } ```</description>