How to make shell script wait for key press to proceed...
Hello.
I'm looking for a way to make my bash shell script stop at certain steps, and continue when a key is pressed. Maybe I'm not searching for the right terms, but google hasn't returned anything useful. Any help is appreciated... |
You can use the read statement. Do you expect the user press a particular key or any key is good to proceed?
|
Quote:
The -n 1 tells read to only read one character (rather than waiting for an ENTER keypress before returning), and -s tells it to be silent (so the key pressed is not echoed on the terminal). |
I think I've found the solution, a combination of "read" and "echo". Thanks anyway!
|
Thanks all for the replies. That was much faster than I'm used to... :)
Colucix, any key pressed would suffice... What's your suggestion? |
Quote:
|
Quote:
Code:
read -p "Press any key to continue... " -n1 -s |
read -p "Press any key..."
|
I just found the -p switch too, and it does exactly what I need it to do. Thanks all for your input!
|
Use read command:
Code:
#!/bin/bash |
WARNING: slightly off-topic:
ddenton, you really need to read man bash - it has lots of useful information. I prefer PDFs to the terminal manpages, especially as each is easily searchable within kpdf Here's a little script to turn manpages into PDF files. There's no error checking. And you had better not have important files called foo.ps or foo.pdf in your current directory, because they'll be removed. Code:
tred@pc:~$ cat man2pdf You'll need to install ps2pdf which for my distro (Kubuntu) comes as part of the package ghostscript. Just use your package manager. Use it like this: ./man2pdf bash Enjoy. |
Tredegar,
I have referred to "man bash" in the past for other shell scripting questions, but the name of the command I needed escaped me. That being said, I really do appreciate everyone's help, even the suggestion to turn man pages into PDF's. It's something I hadn't even though of. Thanks again! P.S. - Once I knew the "read" command was what I needed, I referred to my "Linux in a Nutshell". I'd highly recommend it! It's pretty much man pages in a book. |
Tredeger, I hope you don't mind but I've taken the liberty of modifying your code to add some basic error checking etc:
Code:
#!/bin/bash |
Disillusionist,
That's much better. Thank you :) |
All times are GMT -5. The time now is 04:58 AM. |