Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-01-2009, 05:49 PM   #1
LQ Newbie
Registered: Oct 2008
Posts: 15

Rep: Reputation: 0
Press to Continue

I'm making a script were the user has to enter one of the options: 1, 2, 3 or 4.
After he enters one of the options the script will do something for each(like a menu.

After the output of the chosen option is showed I want the user to be prompted to "Press any key to Continue", So the loop can go back to the menu.

1. add
2. subtract
3. divide
4. exit

Enter: 1

You chose "add"
Press any key to Continue
Old 04-01-2009, 08:52 PM   #2
LQ Newbie
Registered: Oct 2008
Posts: 15

Original Poster
Rep: Reputation: 0
Can anyone pls help.
Old 04-01-2009, 09:03 PM   #3
Senior Member
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,822

Rep: Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610
So what's the problem and what do you have already?
Old 04-01-2009, 09:58 PM   #4
LQ Newbie
Registered: Oct 2008
Posts: 15

Original Poster
Rep: Reputation: 0
I have my full script except the part were i want the user to press a key to continue. I'm looking for a command like "sleep", but the command should end when the user enters any key.
It's just a basic "Press a key to continue"
Old 04-02-2009, 07:18 AM   #5
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 17
Posts: 149

Rep: Reputation: 18
Try this (assuming bash) ...

read -sn 1 junk
The '-sn 1' tells it to read just one character (the n), and to not echo the character (the s). junk is the name of the variable, and since you want it just to add a pause to your script, it is a junk variable. Something that can be thrown away because you don't really care what the user inputs.

Last edited by Hobbletoe; 04-02-2009 at 09:29 AM. Reason: Thought I would add the -s option to the command to prevent the character from being echoed.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Press enter for maintenance (or type Control-D to continue) scg03 Linux - Newbie 2 10-05-2008 12:24 AM
scripting question press any key to continue Mr.McCormick Programming 3 02-04-2005 03:47 AM
boot failed: please change disks and press a key to continue bonovox86uk Red Hat 2 12-08-2004 04:16 PM
Boot failed: please change disk and press a key to continue zeewin Linux - Software 4 01-05-2004 10:39 PM
Boot failed: please change disks and press a key to continue. ChriSchmi Linux - Software 9 03-13-2002 01:34 PM

All times are GMT -5. The time now is 04:43 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration