170

This question already has an answer here:

I'm making a script to install my theme, after it finished installing it will appear the changelog and there will be "Press any key to continue" so that after users read the changelog then press any key to continue

marked as duplicate by Jeff Schaller, Jesse_b, G-Man, Stephen Kitt, schily Jun 8 '18 at 10:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 15
    use less to display your changelog – cas Jul 5 '16 at 7:21
  • 38
    Ugh - don't do that! Installers should not be interactive; nobody wants to sit babysitting when they could have a bunch of stuff queued up to install. Just drop the changelog in your platform's standard location (usually /usr/share/doc/<package>/Changelog) and let them be done with it. For those who want to read every change, they can just install apt-showchanges or equivalent... – Toby Speight Jul 5 '16 at 15:59
  • Well in my country people do differently, so i just make theme installer as simple as possible: choose option to install>let script do it all>after finished installing show the changelog>press any key to exit, it just a script to install my iOS 10 theme on iPhone 3GS by replacing system. I double check the code so that it wont mess up the system, I tried a few install attempt and it works flawlessly – superquanganh Jul 5 '16 at 16:09
  • 15
    but... where's the "any" key? ;) – Florian Castellane Jul 6 '16 at 12:39
  • 5
    if i could edit my comment this late I'd say 'use less to display your changelog, but "Ugh - don't do that! ..."' – cas Jul 6 '16 at 17:18
266

You can use the read command:

read -p "Press enter to continue"

As mentioned in the comments above, this command does actually require the user to press enter; a solution that works with any key would be:

read -n 1 -s -r -p "Press any key to continue"

Explanation by Rayne and wchargin

-n defines the required character count to stop reading

-s hides the user's input

-r causes the string to be interpreted "raw" (without considering backslash escapes)

18

As @cas wrote in a comment, you really should use less for this. If the changelog is more than one page, you really want a pager anyway.

You normally want to consult the PAGER environment variable instead of just calling less:

${PAGER:-less} changelog

will use $PAGER if it is set and less otherwise.

  • Thank you my changelog is not that long, its less than half of iPhone screen (I'm doing script on iPhone) – superquanganh Jul 5 '16 at 9:59
11
read -rsn1 -p"Press any key to continue";echo

Or, if you actually need the REPLY variable:

read -rsn1 -p"Press any key to continue" variable;echo

Replace variable with a variable name you don't need.

  • echo; read -rsn1 -p "Press any key to continue . . ."; echo Oh my gosh... I've done it! I've made Windose! – Andrew Mar 20 at 3:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.