Last active
January 24, 2016 14:37
-
-
Save christophrumpel/1c9b1266eb2a4fc74b03 to your computer and use it in GitHub Desktop.
Shell script read problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
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
Put
$fileinto double quotes, otherwise I think it's alwaysTRUE(at least in bash). You could also usetest -f "$file", which I like more in these kind of situations because it's more clear.I believe
readis not something built into the shell but belongs to the GNU Toolset. Thereadon my OSX does not have the-qswitch 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 :)