Skip to content

Instantly share code, notes, and snippets.

@brujoand
Created October 16, 2019 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brujoand/b1d8296423825e6e47f921316a9c2600 to your computer and use it in GitHub Desktop.
Save brujoand/b1d8296423825e6e47f921316a9c2600 to your computer and use it in GitHub Desktop.
When you need to set a shell variable but don't want the contents displayed anywhere.
#!/usr/bin/env bash
set_secret() {
local variable_name=$1
if [[ -z "$variable_name" ]]; then
read -r -p "Variable name: " variable_name
fi
read -s -r -p "Password: " variable_value
declare -g "$variable_name"="$variable_value"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment