<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">I've written a shell script that's meant to be run similar to how you install rvm[1] using curl:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>$ curl <a href="http://somehost/myscript.sh" class="">http://somehost/myscript.sh</a> | sudo bash -s devel</div><div class=""><br class=""></div><div class="">It's been working great for a couple of months, but I ran into a problem when I tried to add a read prompt. Normally, I don't like doing read statements in a shell script. In this case, I'm using it as a way to allow the user to press enter to skip a timer and reboot the host immediately. If the user does nothing, the host will reboot after 2 minutes. I've also trapped SIGINT so they can ctrl-c to cancel the reboot.</div><div class=""><br class=""></div><div class="">I think I understand the problem - what's happening is that because there's an input pipe to bash, read takes the next line of the script as its input instead of taking it from the user - they're both on stdin. There's what appears to be an answer "Inverting the Fork"[2], but I don't understand the answers.</div><div class=""><br class=""></div><div class="">A simple example[3] showing the difference:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>./pipe_test.sh</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>cat pipe_test.sh | bash</div><div class=""><br class=""></div><div class="">My script is a couple of hundred lines long, and the only part I'm having an issue with is at the very end. I say that because it's been suggested to contain the entire contents of the script in a HEREDOC - that seems way excessive.</div><div class=""><br class=""></div><div class="">Alternatively, I could make the user do</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>$ wget <a href="http://somehost/myscript.sh" class="">http://somehost/myscript.sh</a>; chmod 755 myscript.sh; ./myscript.sh</div><div class=""><br class=""></div><div class="">But that seems far less elegant than curl ... | bash</div><div class=""><br class=""></div><div class="">thanks!</div><div class=""><br class=""></div><div class="">[1] <a href="http://rvm.io" class="">http://rvm.io</a></div><div class="">[2] <a href="http://stackoverflow.com/questions/13763942/bash-why-piping-input-to-read-only-works-when-fed-into-while-read-const" class="">http://stackoverflow.com/questions/13763942/bash-why-piping-input-to-read-only-works-when-fed-into-while-read-const</a></div><div class="">[3] <a href="https://gist.github.com/rjhornsby/dcdaff555d26a00a27b2" class="">https://gist.github.com/rjhornsby/dcdaff555d26a00a27b2</a></div></body></html>