Calling a read from inside a function in a bash shell script causes the script to hang. Can someone explain why this is happening, and how to call read without it? Consider below the MWE.
#!/bin/bash
hangup () {
read choice < /dev/tty
}
hangup
Thank!
Edit: The above, of course, works completely. My problem was extracted from a larger program where I set a variable using the command substitution construct. For example,
myvar=$(hangup)
But there was a loop containing a read call inside the function, and the text was redirected to a variable, so it had a kind of hang, even if something happened - I just could not say because there was no way out (in general, no!).
Sorry for the stupid question. If there is a way to close this question, that would be great.