I have 10 text files with me that I plan on displaying as an output simulating a manual page on how a user could use my script. However I'm looking for the most optimal way in going about displaying the 10 pages page per page.
In example: If a user press 1 on their keyboard they'll be taken to the first page, and if they press 2 on their keyboard they'll be taken to the second page. I originally planned to use a case
structure here. If the user presses 3 it'll open a text file containing my contact info, and if they press 4 they'll go back to the main menu. However considering that I have 10 pages that are to be displayed, it would be very inefficient to use a case
construct on this, I believe.
So to summarize, I would only like to use 1 for the user to go to the previous page, and 2 for the user to go to the next page.
I'm kinda bit of stuck in this part of my script for a while now. Thank you very much!
Every UNIX system has a piece of software that will do this for you -- it's called a pager. Actually most systems have several pagers --
more
, the traditional UNIX one, andless
, the GNU project's modern, featureful take.By convention, a system's user can configure their own pager by setting the environment variable PAGER, so they can even decide to have text displayed in some other piece of software -- a window in their pre-opened editor, a GUI window, a text-to-speech system, or whatever else they use and prefer.
The following is an example of how to select a pager in a robust way.