Operating System - HP-UX
1834425 Members
2120 Online
110067 Solutions
New Discussion

Re: How to pause a script

 
SOLVED
Go to solution
David_246
Trusted Contributor

How to pause a script

Hi,

Anyone any idea how to build a pause into a shell-script.
I know, bad example, but Windows command "pause" says: "Press any key to continue" I'dd like to make it work within a shell script as well.

pause within unix is a C-call, so I can't use it. Thanks for your help in advance.

Regs David
@yourservice
9 REPLIES 9
Ramkumar Devanathan
Honored Contributor
Solution

Re: How to pause a script

use read

$ read

- ramd.
HPE Software Rocks!
Christian Gebhardt
Honored Contributor

Re: How to pause a script

Hi

use

read

Chris
James R. Ferguson
Acclaimed Contributor

Re: How to pause a script

Hi David:

This will work:

# echo "Press Enter to continue...\c"
# read BITBUCKET

...or if you merely wish to "pause" for some number of seconds"

# echo "waiting a bit..."
# sleep 10

...or an HP extension:

# echo "waiting 10 seconds or your response"
# REPLY=`line -t 10`

...in the above, REPLY will be empty if you don't respond in 10-seconds. Otherwise it will be equivalent to a 'read REPLY'.

Regards!

...JRF...



Ramkumar Devanathan
Honored Contributor

Re: How to pause a script

James,

that's a really great answer for a kinda simple question.

Gotta learn that from you.

- ramd.
HPE Software Rocks!
David_246
Trusted Contributor

Re: How to pause a script

Hi James,

This looks very good.
Never knew the REPLY one, great !!

Everybody else, thanks for your quick response !

Regs David
@yourservice
Dario_1
Trusted Contributor

Re: How to pause a script

David:

I agree with everyone, but I have to mention that James answer is a good one. I will add that one to my collection.

Regards,

DR
James R. Ferguson
Acclaimed Contributor

Re: How to pause a script

Hi (again) David:

I would be remiss if I didn't point out that the man pages for 'line' make this warning:

"This command is likely to be withdrawn from X/Open standards. Applications using this command might not be portable to other vendors' systems. As an alternative read is recommended."

Regards!

...JRF...
David_246
Trusted Contributor

Re: How to pause a script

Yep, you're right. We'll use the read one then, but the "line -t <.>" is defintly a to_know one.

Many thanks mister Olympian! :)


Regs David
@yourservice
RolandH
Honored Contributor

Re: How to pause a script

If you want something what will also work on other systems ( I use this on sun systems ) you can do something like this:
....
echo "Choose:y|n \c"

RET=`((sleep 20; echo timeout)& cat -u 2>&-) | (read xxx;echo "$xxx")`

fi

case $RET in
y|Y) do_something ;;
n|N) do_somthing ;;
timeout ) default ;;
esac
......

That about the same as line -t
Sometimes you lose and sometimes the others win