: I have to accept user password using ksh and the script should echo
: out "*" for every character input. I am having problem detecting the
: end-of-password ( when the user presses the enter key)
: Here is the script.
: echo "enter password:\c "
: stty -echo
: stty raw
: while [[ "$ch" != "x" ]]; ## i need to catch the newline here instead
: of 'x'
First, the LHS of a conditional expression, or the single parameter of a
conditional expression option, never needs to be quoted.
[[ $x = "$y" ]]
[[ -z $x ]]
will never fail unexpectedly.
Second, IFS is NEVER inherited in ksh (that was an old security hole
with setuid scripts. Although setuid scripts are widely disallowed, the
fix remains. For instance, with a setuid Bourne sh script you could
set IFS=/ to plant a trojan if the PATH was not explicitly set in the script).
So IFS, unless explicitly changed, is space-tab-newline. So you can get
a newline character by stripping off the first two characters:
However, in raw mode, the character you want to be looking for is
cr="$(print -n "\r")"
: ch=`dd bs=1 count=1 2> /dev/null`
: print -n "*"
: stty -raw
: stty echo
: echo "the password is "$pass