How to introduce delay in Shell Script till a key stroke.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to introduce delay in Shell Script till a key stroke.
# 1  
Old 08-25-2010
Debian How to introduce delay in Shell Script till a key stroke.

Hi All,

How to introduce delay in the Bash/Shell Script till key stroke.
Below is the requirement..

1.Execute set of commands.
2.Display the message echo "press any key to continue"
Introduce a delay till key stroke.
3.Execute next set of commands.

Thanks in Advance

Sunil.K
# 2  
Old 08-25-2010
Misunderstood, nvm.

Last edited by bartus11; 08-25-2010 at 06:47 AM..
# 3  
Old 08-25-2010
This User Gave Thanks to Scott For This Post:
# 4  
Old 08-25-2010
Or if your shell supports this option:
Code:
read -t

# 5  
Old 08-25-2010
I wrote a function to handle different cases of pause in shell scripts. You can simplify it for your needs.
Code:
pause()	{	# [1:timeout] [2:prompt]
	local P T
	[[ $1 =~ ^[0-9]+$ ]] && { T=$1; shift; }
	P=${1:-Hit any key...}
     echo -n "$P " >&2
     if ((T))
     then	for ((P=$T; P>0; P--))
		do	read -sn 1 -p "($P) " -t 1 && break
			tput cub $((${#P}+3))
		done
	else
		read -sn 1
	fi
	echo >&2
	return
}

Default prompt is given if none provided.
The plus is that it displays a countdown.
You can call it like
Code:
pause 10

to pause 10 seconds
if no time is given it just waits for hitting a key.
I put this in a .bash_env file which is sourced by any bash scripts; i put also somme other little functions and constants who are used in several scripts.
This User Gave Thanks to frans For This Post:
# 6  
Old 09-28-2010
Thanks for the HELP....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass Enter key stroke , tried all options?

Hi Friends, I am unable to pass Enter key stroke to shell script. Tried all options, but no luck. Please help.. Script: bkpscript.sh tam01# ./bkpscript.sh < file.txt Mount volume 1 on /dev/rmt0. Press Enter to continue. tam01# tam01# tam01# tam01# echo ""... (5 Replies)
Discussion started by: suresh3566
5 Replies

2. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

3. UNIX for Dummies Questions & Answers

Shell Script for displaying the line till the target word

" Script for display sentences with special character" Hi, Could any one share a command how to display a line until my target word. For ex: My file has the content as: select * from db_wrk where col1 < col2 insert into table_name values('1','2','tst','wrk','dev','prod') My target... (10 Replies)
Discussion started by: Kalaiselvi66
10 Replies

4. Shell Programming and Scripting

How do I do a short delay (milliseconds) in a shell script?

I need to put a small delay into a shell script. I'm looking for something smaller than "sleep" - a second is way too long. I want to sleep something like 10 milliseconds. I've tried "usleep" and "nanosleep", but the script doesn't recognize them. I'm using the bash shell but I'm willing to... (9 Replies)
Discussion started by: harmlesscat
9 Replies

5. Shell Programming and Scripting

Pause shell script till folder doesn't change size anymore

Hi, I recently would like to write a shell script that 1. Runs in the background (can be done with "&", but i'd be happy for other solutions to keep programs running) 2. Does its stuff 3 THEN checks a specified folder for a size change over time (say, each 5 seconds. AND ONLY continues with... (9 Replies)
Discussion started by: pasc
9 Replies

6. Shell Programming and Scripting

Want to have delay in multiple instances of the same shell script

Hello, My goal is to run the same Shell script in a parallel mode. This script will get triggered from different machines and different application teams by some job scheduling tool. They may trigger the process at the same time. so I want to have them in QUEUE ..and release them for execution on... (3 Replies)
Discussion started by: chetan_sonar
3 Replies

7. Shell Programming and Scripting

Want read and an built in enter key stroke

i have script like: echo "enter name" read a I do not want to press enter key i have tried with ascill of enter as (\013) but still it wait for enter , please resolve my problem (2 Replies)
Discussion started by: RahulJoshi
2 Replies

8. Shell Programming and Scripting

how to introduce delay in the script??(urgent)

Hi all, i would like to know how to introduce a delay in the execution of a cmd? am trying to copy a file which is about 650 mb and then perform some actions on it.. however since its huge i would like to introduce a delay in exection until the process is over i dont want it to proceed to... (10 Replies)
Discussion started by: wrapster
10 Replies

9. UNIX for Dummies Questions & Answers

key stroke in sco unix

Hi, Please tell me substitute for esc+\ (used in solaris) in case of sco unix. Thanks, Pintu (1 Reply)
Discussion started by: pintupatro
1 Replies

10. UNIX for Advanced & Expert Users

using enter key in shell script

without pressing the enter key ..manually... how can we read the enter key ..from the shell script..so that the script termintes automatically. eg: telnet a.b.c.d xxxx now " how to read the enter key" tho terminate the script (1 Reply)
Discussion started by: bishweshwar
1 Replies
Login or Register to Ask a Question