Skip to content

Instantly share code, notes, and snippets.

@christophrumpel
Last active January 24, 2016 14:37
Show Gist options
  • Save christophrumpel/1c9b1266eb2a4fc74b03 to your computer and use it in GitHub Desktop.
Save christophrumpel/1c9b1266eb2a4fc74b03 to your computer and use it in GitHub Desktop.
Shell script read problem
Need to check input from the user in a script.
It seems there is no read version that works for zsh and normal bash.
(Error when using bash: read:27: -p: no coprocess with zsh)
This is why I tried to check if .zshrc file is given and depending on that I choose the read command.
But even if I try it like this, I get the error "read:27: -p: no coprocess" even if it shoudln't get called
because the file is given.
[ -f $file ] && read -q "reply?Answer: " || read -r -p "Answer: " reply
@Sgoettschkes
Copy link

Put $file into double quotes, otherwise I think it's always TRUE (at least in bash). You could also use test -f "$file", which I like more in these kind of situations because it's more clear.

I believe read is not something built into the shell but belongs to the GNU Toolset. The read on my OSX does not have the -q switch at all. Given I have no idea what read really does, maybe you could explain what the thing should do and then we could try to find a solution :)

@christophrumpel
Copy link
Author

Hey, thx for reply. $file was just a placeholder, but thx form mentioning it.
What I am trying to do is just a simple input in a script to make sure the user really wants to trigger it.
Just a simple YES or NO question. Is there a better way without the read command?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment