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" nameThank 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:
More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"