Netsu
Netsu

Reputation: 363

How pipe to zsh read?

With bash everything is fine:

$ yes | bash -c 'read -sn 1 -p "[Y/n] " RESPONSE ; echo $RESPONSE'
y

But with zsh I have trouble:

$ yes | zsh -c 'read -sk 1 "RESPONSE?[Y/n] " ; echo $RESPONSE'
[Y/n]

Upvotes: 2

Views: 2041

Answers (1)

qqx
qqx

Reputation: 19475

When the -k option is used, zsh's read command will read from the terminal unless instructed otherwise. This is documented in the appropriate section of the zshbuiltins manpage. Your pipe is supplying the standard input for the script, but that has no effect on attempts to read from the terminal.

You can add -u 0 to the call to read to tell it to read from standard input (file descriptor 0) even when other options (such as -k) would cause it to read from elsewhere.

Upvotes: 3

Related Questions