read -n1 -r -p "Press..." key / produces error in bash shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read -n1 -r -p "Press..." key / produces error in bash shell script
# 1  
Old 05-26-2010
read -n1 -r -p "Press..." key / produces error in bash shell script

Hello!

Sorry, for my not so perfect english!

I want to stop bash shell script execution until any key is pressed.

This line in a bash shell script

Code:
read -n1 -r -p "Press any key to continue..." key

produces this error

Quote:
read: 1: Illegal option -n
When I run this from the command line

Code:
usera@lynx:~$ read -n1 -r -p "Press any key to continue..." key
usera@lynx:~$

it works without error.

What do I wrong?
# 2  
Old 05-26-2010
it seems to working fine for me
Code:
$cat key.sh
#!/bin/sh                                                                       
read -n5 -rp "Press any key to continue..." key                                 
echo -e "\n Pressed key is : $key"    
$. key.sh
Press any key to continue...world
 Pressed key is : world

could you post snippet ..
# 3  
Old 05-26-2010
Thanks your reply!

It works!

But not my script. There must be a fault before "read -n1....." in my script.

I'm giving up fore today.

Letting things go.

Tomorrow it will work. I hope.

Thanks for your support!
# 4  
Old 05-26-2010
Make sure you are running it in the BASH shell, #!/bin/bash, other shells may not support these options.
# 5  
Old 05-26-2010
Thanks for all repleys!

Sorry!
Mea culpa, mea culpa maxima!

It makes the difference!

Code:
#!/bin/bash

or

Code:
#!bin/sh

Just 3 seconds not concentrated. S..t happens!

Again Thanks for support, and Sorry!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Script that automatically issue "yes" and press enter

Team, Got a thousand servers. I created a script to say hello on every server. But is there a script or whatever that will issue a yes on every key checking. for i in `cat myserverlist` do echo $i ssh-copy-id $i done The authenticity of host 'server1 (162.162.0.10)' can't be... (7 Replies)
Discussion started by: invinzin21
7 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. UNIX for Dummies Questions & Answers

"Help with bash script" - "License Server and Patch Updates"

Hi All, I'm completely new to bash scripting and still learning my way through albeit vey slowly. I need to know where to insert my server names', my ip address numbers through out the script alas to no avail. I'm also searching on how to save .sh (bash shell) script properly.... (25 Replies)
Discussion started by: profileuser
25 Replies

5. Shell Programming and Scripting

Shell script using expect to login to couple of remote servers and read "crontab -l"

I need a shell script using expect to login to couple of remote servers and read "crontab -l -u <username>" & "cat /etc/rc.local" & "df -h" and able to create output into a file saved locally with hostname.crontab & hostname.rc.local & disk.status. I can supply a file as list of hostname or IP... (4 Replies)
Discussion started by: jaipsharma
4 Replies

6. Shell Programming and Scripting

speeding up bash script with "while read line"

Hello everybody, I'm still slowly treading my way into bash scripting (without any prior programming experience) and hence my code is mostly what some might call "creative" if they meant well :D I have created a script that serves its purpose but it does so very slowly, since it needs to work... (4 Replies)
Discussion started by: origamisven
4 Replies

7. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

8. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

9. Shell Programming and Scripting

How does BASH handle KEY BOARD "up arrow"??

hello sir, I am studying the BASH shell. I was wondering how the BASH is able to handle the "up arrow" key to give the commands that were previously typed by us. Can you please tell me the code to do such an operation. I want to handle more such keys and put KEY BOARD short cuts to the BASH shell. (1 Reply)
Discussion started by: nsharath
1 Replies

10. Shell Programming and Scripting

How to include RETURN KEY with Background process "&" in Shell Script

Hello All, I am a newbie in Shell script programming, and maybe you can help me with my query. I need to write a shell script (mntServer.ksh) that will start a background process and also to be able to run another script. The mntServer.ksh script contains: #!/bin/ksh... (1 Reply)
Discussion started by: racbern
1 Replies
Login or Register to Ask a Question