3

I can hide what is written in a terminal with bash with

stty -echo

This is however not working for zsh: running this command does not change the output of

stty -a

What is the equivalent command of stty -echo for zsh?

  • Why would you want to do that? – ilkkachu Feb 8 '17 at 21:43
  • N.B. Bash has its own policy for stty. See this question. – teika kazura Feb 23 '17 at 4:39
  • Some use cases: reading in passwords, direction controls for a game written in bash. – Att Righ Mar 8 '17 at 20:21
3

I think zsh resets the terminal when returning to the prompt. Which is actually really useful since it prevents you from getting stuck in the prompt with a broken terminal and having to cast strange incantations to restore sanity.

According to a mailing list discussion, you can make it not do that at the expense of disabling line editing completely with unsetopt ZLE.

2

By default, the terminal configuration associated with the current session is frozen, so most settings done with stty are ephemeral.

According to zsh documentation, you can unfroze your terminal with this command

ttyctl -u

and revert to the regular, frozen mode with:

ttyctl -f 

In unfrozen mode, your stty settings are supposed to persist. It doesn't seems to be the case with -echo though.

However, if your goal is to temporarily disable echoing characters for a single command or an external program, the default behavior might be sufficient:

$ stty -echo;stty -a;read foo
speed 38400 baud; rows 44; columns 165; line = 0;
intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl -echoke
$ echo $foo
abc

Note that stty reports the -echo setting and the characters typed in reply to the read command weren't echo'ed to the screen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.