|
|||||||||
| Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here. |
learn linux and unix commands - unix shell scripting |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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! |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Try this:
echo -n "Press Enter: "; read MyVar; echo $MyVar $MyVar will be whatever you type, but just hitting enter will print nothing |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
Quote:
|
|
#4
|
||||
|
||||
|
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. |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
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 )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! |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
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. |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
How can I write a command right after an echo. It`s not working:
echo "Date : " `date + %d` Am I writing it wrong? |
| Sponsored Links | ||
|
|
![]() |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to have ENTER after each symbol. | sparkriver | Shell Programming and Scripting | 5 | 01-30-2009 01:21 PM |
| Enter to OBP | jess_t03 | Solaris | 5 | 02-13-2008 12:14 PM |
| read the ENTER key | sars | Shell Programming and Scripting | 4 | 11-27-2006 08:34 AM |
| Cant enter password | possuman72 | Solaris | 2 | 06-10-2005 03:44 PM |
|
|