* Re: Reading without echo?
2001-05-09 9:27 Reading without echo? John S Cooper
@ 2001-05-09 9:23 ` Peter Stephenson
2001-05-09 15:56 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2001-05-09 9:23 UTC (permalink / raw)
To: Zsh users list
John S Cooper <John.Cooper@eu.citrix.com> wrote:
> What's the recommended way for a zsh script to read (with prompt) a password
> without having it echo'd?
You need to do something like:
stty -echo; read pw?'Password> '; stty echo; print
There's no internal support for this (actually that's not quite true since
the zftp module can read passwords, but there's no way to this from the
main shell).
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
^ permalink raw reply [flat|nested] 3+ messages in thread
* Reading without echo?
@ 2001-05-09 9:27 John S Cooper
2001-05-09 9:23 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: John S Cooper @ 2001-05-09 9:27 UTC (permalink / raw)
To: Zsh users list
What's the recommended way for a zsh script to read (with prompt) a password
without having it echo'd?
Thanks,
--- John
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Reading without echo?
2001-05-09 9:23 ` Peter Stephenson
@ 2001-05-09 15:56 ` Bart Schaefer
0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2001-05-09 15:56 UTC (permalink / raw)
To: Zsh users list
On May 9, 10:23am, Peter Stephenson wrote:
} Subject: Re: Reading without echo?
}
} John S Cooper <John.Cooper@eu.citrix.com> wrote:
} > What's the recommended way for a zsh script to read (with prompt) a
} > password without having it echo'd?
}
} You need to do something like:
}
} stty -echo; read pw?'Password> '; stty echo; print
The problem with this (aside from the "no match" error because the `?'
is outside the quotes) is that if you interrupt it, e.g. with ^C, the
terminal may be left in no-echo mode for some period of time. However,
ZLE does eventually force echo back on (even for external commands and
even when the tty is not frozen with ttyctl, which surprises me a bit).
} There's no internal support for this (actually that's not quite true since
} the zftp module can read passwords, but there's no way to this from the
} main shell).
Actually, there is internal support for this, of a sort. Look at the STTY
parameter. Unfortunately, STTY applies only to external commands, not
shell builtins, so you can't just do `STTY=-echo read ...'.
This should probably be considered a bug, because zsh does execute the
`stty -echo' command even though the resulting settings don't apply to
the `read' when it happens.
Anyway, something like
print -n 'Password> '; STTY=-echo head -1 | read pw
is supposed to safely set and restore no-echo mode. However, I just tried
it, and it has the same problem as Peter's suggestion -- the tty modes are
not restored if the command is interrupted. (To see this happen, you must
`unsetopt ZLE'.)
In fact, `ttyctl -f' seems to be nonfunctional when ZLE is disabled, too.
So the only way I could actually "recommend" for doing this is along the
lines of:
getpass () {
setopt localoptions localtraps
trap "stty echo" EXIT HUP INT QUIT
{ stty -echo
read "$@"
print
} </dev/tty >&/dev/tty
}
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-05-09 15:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-09 9:27 Reading without echo? John S Cooper
2001-05-09 9:23 ` Peter Stephenson
2001-05-09 15:56 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).