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
3 Answers
You can use the read
command. If you are using bash
:
read -p "Press enter to continue"
In other shells, you can do:
printf "%s " "Press enter to continue"
read ans
As mentioned in the comments above, this command does actually require the user to press enter; a solution that works with any key in bash
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.– JortstekMay 2, 2020 at 9:05 -
1this helped me when I ran into the "no coprocess" error in zsh unix.stackexchange.com/questions/198372/… Jul 29, 2020 at 21:59
-
If you got here because somebody integrated this into their code (for example
abook --add-email-quiet
), and you need a workaround, pipeyes | thecommand
. May 16, 2021 at 11:42 -
1Yes, but I would add (like suggested by @EKons) to incl. ";echo" at the end, as it is more elegant, it brings the terminal back to a fresh new line. just my 2 cents– aviaJul 11, 2021 at 8:31
-
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.
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) Jul 5, 2016 at 9:59
less
to display your changelog/usr/share/doc/<package>/Changelog
) and let them be done with it. For those who want to read every change, they can just installapt-showchanges
or equivalent...