On 2020-08-01, Michael Welle <
mwe0...@gmx.net> wrote:
> Hello,
>
> I want to read in a password from keyboard. Switching the local echo off
> for that would be a nice feature. All experiments with stty -echo or
> setty were not successful, neither on Linux nor on Solaris. With ksh,
> for instance, it works as expected. Any idea how to read in a password
> without local echo with (t)csh, please?
You can't really experiment with stty in the interactive mode of a shell
like Bash, because that keeps saving and restoring the TTY settings
between its own command prompt and the job it puts into the foreground.
All the stty actions you require have to be put into the same command
line to be run together in the same job. It will definitely work.
It's probably best to put this into its own script, which uses "trap" to
install a handler which restores the termios settings on exit or abrupt
termination.
The GNU coreutils stty has a -g option which produces the state of
termios encoded as a character string. The string can be passed as an
argument to stty again to restore the tty to those settings.
The Solaris stty has this also.
I have both in a Solaris 10 installation; the Solaris one reports a
larger string.
0:solarflare:~$ /usr/bin/stty -g
2d02:5:f04bf:8a3b:3:1c:7f:15:4:ff:ff:0:11:13:1a:19:12:f:17:16:0:0:1:1:0:00:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
0:solarflare:~$ /opt/csw/bin/stty -g
2d02:5:f04bf:8a3b:3:1c:7f:15:4:ff:ff:0:11:13:1a:19:12:f:17:16:0:0:0
If the -g option is available, it should be the preferred mechanism
for restoring the TTY settings.
Side remark:
There is an old C library function called getpass for doing this.
The Single Unix Specificatio marked it as "legacy" in the 1990's.
POSIX removed it in 2001.
I'm not aware of a command utility wrapper around getpass.