How can I make "Press any key to continue"

  • 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

    use `less` to display your changelog

    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//Changelog`) and let them be done with it. For those who want to read every change, they can just install `apt-showchanges` or equivalent...

    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

    but... where's the "any" key? ;)

    if i could edit my comment this late I'd say 'use less to display your changelog, but "Ugh - don't do that! ..."'

    His other problem: the iPhone does not have any keys.

    The onscreen keyboard of iPhone still work with "press any key to continue"

    Interactive mode would be a useful addition to the command line arguments, just off by default.

  • MKT

    MKT Correct answer

    4 years ago

    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)

    Then what after the `read` statement? Seems to be missing the following line.

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM