Skip to content

Instantly share code, notes, and snippets.

@surgiie
Created November 13, 2025 23:03
Show Gist options
  • Select an option

  • Save surgiie/cc3f689c049d02bb84f999e1a813aa34 to your computer and use it in GitHub Desktop.

Select an option

Save surgiie/cc3f689c049d02bb84f999e1a813aa34 to your computer and use it in GitHub Desktop.
Ask for secret input via function and while redirecting output to stdout still instead of being lost in subshell
## Ask secret input
ask_secret() {
local prompt="$1"
local input confirm
read -s -p "$(yellow_bold '[INPUT]'): $prompt " input >&2
echo >&2
read -s -p "$(yellow_bold '[CONFIRM]'): Confirm input: " confirm >&2
echo >&2
if [[ "$input" != "$confirm" ]]; then
error 'Inputs do not match.' >&2
exit 1
fi
echo "$input"
}
secret=$(ask_secret "Enter secret")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment