Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: hiding input text



What's wrong with stty -echo? Ok, it is not portable (works only on Unix),
perhaps someone has a portable solution... Here is a quick and dirty
getpass function. It should perhaps have a trap to restore the terminal
modes on exit. And I found no other way to get a newline in a string than
to use single quotes (I tried \n and echo but did not succeed).

Hope this helps

--Swen


#!/usr/bin/zsh

function getpass() {
  echo -n "Password: "
  stty -echo
  key=""
  end='
'
  while ( true ); do
    read -k key
    if [[ "$key" == "$end" ]]; then
      break
    fi
    echo -n .
    pass="$pass$key"
  done
  echo
  stty echo
}

getpass
echo "Password was $pass"




Messages sorted by: Reverse Date, Date, Thread, Author