M BUZZ CRAZE NEWS
// general

zsh: read:-p: no coprocess error while using read command with -p flag

By Emma Martinez

community. I recently started to use zsh instead of bash and now i'm getting some problems that cannot be found on bash. One of theme: when i use read -p command, obviously with flag -p, i get an error that says:

read: -p: no coprocess

On the other hand when I switch to bash again, this command works perfectly.

My full command:

read -p "what's your name" name

Thank you for help <3

1 Answer

The usage is not compatible between shells.

As explained in man zshbuiltins, the way to emit a prompt string for a zsh read command is to append it to the identifier name after a ?:

 If the first argument contains a `?', the remainder of this word is used as a prompt on standard error when the shell is interac‐ tive.

So for example

 % read name\?"what's your name? "
what's your name? 

(the ? needs to be escaped here to prevent the shell treating it as a globbing character) or

 % read "name?what's your name? "
what's your name? 

See also:

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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