• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Search

typing

Display Asterisks When Typing Passwords in Bash

September 18, 2023

Here’s how to display asterisks when typing passwords in Bash.

#!/bin/bash
unset password
prompt="Enter Password:"
while IFS= read -p "$prompt" -r -s -n 1 char
do
    if [[ $char == $'\0' ]]
    then
        break
    fi
    prompt='*'
    password+="$char"
done
echo
echo "Done. Password=$password"

#!/bin/bash unset password prompt="Enter Password:" while IFS= read -p "$prompt" -r -s -n 1 char do if [[ $char == $'\0' ]] then break fi prompt='*' password+="$char" done echo echo "Done. Password=$password"

Filed Under: Linux Tagged With: asterisks, bash, display, password, typing

  • Home
  • About
  • Search

Copyright © 2023