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?
I have a Bash shell script in which I would like to pause execution
Share
readdoes this:The
-n1specifies that it only waits for a single character. The-rputs it into raw mode, which is necessary because otherwise, if you press something like backslash, it doesn’t register until you hit the next key. The-pspecifies the prompt, which must be quoted if it contains spaces. Thekeyargument is only necessary if you want to know which key they pressed, in which case you can access it through$key.If you are using Bash, you can also specify a timeout with
-t, which causes read to return a failure when a key isn’t pressed. So for example: