#!/bin/sh # Demonstrate reading passwords in a shell script # while not echoing those passwords to the screen. # License: LGPLv2 # Note `read -s` in bash 3 at least does not echo # the return/newline either? Therefore we need to # `echo >&2` after each read to simulate that. proc getpassword { while not test $password = $rpassword -a -n $password { read -s -p "Enter a password for user '$1' : " password; echo > !2 read -s -p "Reenter password for user '$1' : " rpassword; echo > !2 } echo $password } setglobal pw = $[getpassword $(1:-blah)] echo "password is '$pw'"