Pressing Enter (bash)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pressing Enter (bash)
# 1  
Old 02-07-2009
Pressing Enter (bash)

Hey, I'm writing this BASH script, I recently started learning BASH after I did Java and I'm pretty new to the syntax.

Anways, what I want to do is simple, I coudn't find the right information though:

Let's say I make a :

read -p "Press ENTER to go back to menu" choice
.....


What is the command that would let me perform this? I need to way for the User to press ENTER, not a silly Y/N. (It's for general accomplishment actually haha).

-Yakuzan

P.S : Example much appreciated!
# 2  
Old 02-07-2009
Try this:
echo -n "Press Enter: "; read MyVar; echo $MyVar

$MyVar will be whatever you type, but just hitting enter will print nothing
# 3  
Old 02-07-2009
Quote:
Originally Posted by Yakuzan
Hey, I'm writing this BASH script, I recently started learning BASH after I did Java and I'm pretty new to the syntax.

Anways, what I want to do is simple, I coudn't find the right information though:

Let's say I make a :

read -p "Press ENTER to go back to menu" choice
.....


What is the command that would let me perform this? I need to way for the User to press ENTER, not a silly Y/N. (It's for general accomplishment actually haha).

Your code will work as is.

The script will wait until the user presses ENTER. You might add an -s option to prevent any other characters being echoed to the screen, and you don't need a variable name since you aren't going to check it:

Code:
read -sp "Press ENTER to go back to menu"
echo "Thank you!"

# 4  
Old 02-07-2009
Wasn't sure if Yakuzan needed to take in a Menu Choice or not...

I was assuming that was the point. Take in choice if given, else just do nothing.

You are correct though either way Yakuzan's original code will work as is and will even store the response in choice if needed.
# 5  
Old 02-07-2009
Il use this thread to ask most of my questions since my Linux book blows. It only covers basic BASH since it's not a BASH guide.

And since my openSUSE doesn't have internet on it I'm stuck going from one system to another.

Btw, to understand my concept:

1- Show date
2- Move a folder
3- See current location

That is the menu which is a script called ./menu
If the script reads 1 then you get shoot to ./date
Then I ask to press enter to show back the menu(Thanks a lot Smilie)
Then back to ./menu

Excetera, each number has it's own script.

As to todays question:

Is there a way to force the user to press enter and nothing else? Does it require an if statement? I saw you mention -s, what exactly do you mean?

P.S Huge thanks to you guys, I'm spending a few hours a day on BASH, Il get it sorted out in no time!
# 6  
Old 02-07-2009
The -p flag is prompt (basically use the following text as the prompt)
The -s flag is silent mode (do not echo characters to the screen)

As to forcing the user to press "Enter" only... why?
No matter what they press it will either be passed to a variable ($choice in you example), or completely discarded as in cfajohnson's example.

Either way Enter was pressed and if you do not use $choice (in you example) the rest doesn't matter.
# 7  
Old 02-07-2009
How can I write a command right after an echo. It`s not working:

echo "Date : " `date + %d`

Am I writing it wrong?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script termination without pressing Enter key[nohup]

I have a script in which we have used nohup. Once script is executed it will be terminated only when enter key is pressed. I want the script to be terminated without pressing enter key nohup imqbrokerd -name user_id port 2>1 1>$home_`date` & I am a newbie to shell, Kindly please help (3 Replies)
Discussion started by: Suganbabu
3 Replies

2. Shell Programming and Scripting

Input password to bash script, save, and enter when needed

I am looking for a way to start a script and have it prompt for a password that will be used later on in the script to SSH to another host and to SFTP. I don't want the password to be hard coded. Below is my script with the actual IP's and usernames removed. #!/usr/bin/expect -f... (2 Replies)
Discussion started by: jbrass
2 Replies

3. Shell Programming and Scripting

How to pass enter key or selected character in bash script?

hi, i've bash script thats working... but now i need to add a line....that prompts for user input....like yes and 1 as complete install.... so here's how it looks... $ cd 9200 (cd into directory) $./install (hv to type ./install to run install then ask for) ----do you want to... (4 Replies)
Discussion started by: kernel11
4 Replies

4. Shell Programming and Scripting

Perl - start search by using search button or by pressing the enter key

#Build label and text box $main->Label( -text => "Input string below:" )->pack(); $main->Entry( -textvariable => \$text456 )->pack(); $main->Button( -text => "Search", -command => sub { errchk ($text456) ... (4 Replies)
Discussion started by: popeye
4 Replies

5. Shell Programming and Scripting

Want to write a command that keeps pressing enter key in regular interval

Hi, I m new to linux, can you pls help me to write a command/ script that keeps pressing the enter key in regular interval. Thx, Linux1 (2 Replies)
Discussion started by: mylinux1
2 Replies

6. Shell Programming and Scripting

Pressing enter and script still goes on

i have a bash shell script and i press enter and the script still continues on? how do i stop this (3 Replies)
Discussion started by: gangsta
3 Replies

7. Shell Programming and Scripting

How to enter a return key in bash script?

Hi, I'm porting an install script from AIX to Red Hat (2.6.18-164.el5 #1 SMP) I have this script working in both AIX and HP-UX. The script is a wrapper for a Micro Focus Server Express install program. It responds to the install program questions with a here-now list. Responses includes... (14 Replies)
Discussion started by: duker61
14 Replies

8. Shell Programming and Scripting

Pressing "Enter/Space bar" using Net::TELNET? in Perl

I'm trying to learn how to get my script to execute the enter button when it telnets into a router and the router displays output but you need to press the space bar or enter button to continue displaying my output of the router. How is this done? (0 Replies)
Discussion started by: xmaverick
0 Replies

9. Shell Programming and Scripting

BASH: Any Way to Get User Input Without Requiring Them to Hit the Enter Key?

I'm working on making a menu system on an HP-UX box with Bash on it. The old menu system presents the users with a standard text menu with numbers to make selections. I'm re-working the system and I would like to provide something more akin to iterative search in Emacs. I have a list of 28... (2 Replies)
Discussion started by: deckard
2 Replies

10. UNIX for Dummies Questions & Answers

Pressing backspace key simulates enter key

Hi, Whenever i press the backspace key, a new line appears, i.e. it works like a enter key. :confused: Thanks (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies
Login or Register to Ask a Question