How to make shell script wait for key press to proceed...
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
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...
Bash has a builtin command, "read" (check out 'man read'). You can cause bash to wait for a keypress by using 'read -n 1 -s'
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).
#!/bin/bash
read var_year
echo "The year is: $var_year"
echo -n "Enter your name and press [ENTER]: "
read var_name
echo "Your name is: $var_name"
echo -n "Press [ENTER] to continue,...: "
read var_name
echo "You can go on!...."
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
#!/bin/bash
# A very sloppy script to generate man pages as pdf files
man -t $1 > foo.ps && ps2pdf foo.ps && rm foo.ps && mv foo.pdf $1.pdf
kpdf $1.pdf &
tred@pc:~$
I just saved the script to my home directory, and made it executable.
You'll need to install ps2pdf which for my distro (Kubuntu) comes as part of the package ghostscript. Just use your package manager.
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
###
###
usage(){
echo "usage:- man2pdf [manpage]"
}
create_pdf(){
man -t $manpage > /tmp/${manpage}.ps && ps2pdf /tmp/${manpage}.ps
if [ $? -ne 0 ]
then
## even if the ${manpage} man page doesn't exist
## /tmp/${manpage}.ps would have been created, so tidy-up
rm -f /tmp/${manpage}.ps
exit 1
else
## remove temporary file
rm -f /tmp/${manpage}.ps
fi
}
manpage=$1
if [ "$manpage" == "" ]
then
usage
exit 2
fi
if [ -f ${manpage}.pdf ]
then
read -p "${manpage}.pdf file exists, do you want to replace it?:" ans_yn
case "$ans_yn" in
[Yy]|[Yy][Ee][Ss]) echo "Replacing ${manpage}.pdf ...";;
*) exit 3;;
esac
fi
create_pdf
Last edited by Disillusionist; 12-01-2008 at 03:32 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.