Skip to content

Instantly share code, notes, and snippets.

@GlitchedPolygons
Last active May 7, 2021 08:20
Show Gist options
  • Save GlitchedPolygons/8e2e6df19c9ff108b7f47429589b7ca3 to your computer and use it in GitHub Desktop.
Save GlitchedPolygons/8e2e6df19c9ff108b7f47429589b7ca3 to your computer and use it in GitHub Desktop.
Linux CLI shell script snippet for prompting the user for a password (with confirmation and empty-check).
while true; do
echo
read -s -p "Enter the desired password: " PASSWORD
echo
read -s -p "Confirm your password by re-entering it again: " PASSWORD_CONFIRMATION
echo
[ "$PASSWORD" = "$PASSWORD_CONFIRMATION" ] && break || echo " ----- The two entered passwords don't match; please try again! -----"
done
if [ -z "$PASSWORD" ]; then
echo
echo "ERROR: Password can't (and shouldn't...) be empty! Please provide a valid value!"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment