I have a Bash shell script in which I would like to pause execution until the user presses a key. In DOS, this is easily accomplished with the "pause" command. Is there a Linux equivalent I can use in my script?
相关问题
- How to get the return code of a shell script in lu
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- JQ: Select when attribute value exists in a bash a
- Invoking Mirth Connect CLI with Powershell script
If you just need to pause a loop or script, and you're happy to press Enter instead of any key, then
read
on its own will do the job.It's not end-user friendly, but may be enough in cases where you're writing a quick script for yourself, and you need to pause it to do something manually in the background.
Yes to using
read
- and there are a couple of tweaks that make it most useful in bothcron
and in the terminal.Example:
The -n 120 makes the read statement time out after 2 minutes so it does not block in
cron
.In terminal it gives 2 minutes to see how long the
rsync
command took to execute.Then the subsequent
echo
is so the subsequent bash prompt will appear on the next line.Otherwise it will show on the same line directly after "continue..." when Enter is pressed in terminal.
Try this: