Created
November 13, 2025 23:03
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 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