Skip to content

Instantly share code, notes, and snippets.

View duxsco's full-sized avatar

David Sardari duxsco

View GitHub Profile
duxsco /
Last active May 8, 2022 23:50
Prevent "tainting" Bash script variables via environment

I decided to use following convention for variables in my Bash scripts:

A) Variables are written without curly brackets if:

  • They are fine to be set via environment, e.g. $HOME
  • The environment doesn't play a role, e.g. $OPTARG whose value is set by getopts

B) All other variables are written with curly brackets, e.g.: ${KERNEL_VERSION}

Variables that fall under scenario B) are unset at the beginning of the Bash script.

duxsco /
Created February 28, 2023 18:37
Proof for Keyoxide