Last time I went through some general scripting concepts and recommendations, leaning towards Bash (or ‘shell’) scripting. I know you’re itching to get started with scripting, but how do you know what each command does, and what ‘arguments’ are available with each command. Step in the man pages.
Man pages – What are they and how do I find them?
Each command used in terminal (and so usable in bash scripting) comes with an information page to help describe its primary function and any options that can be used. These information pages are referred to as the ‘man’ pages (short for manual).
The simplest way to access these pages is with the command “man [command]”. For example, to view the man page for the grep command, you would enter the following into Terminal:
This should display something close to the following:
This will take over your Terminal window with lots of information on the usage and options. Further down, you’ll often find examples, exit status codes, and bug reports.
To navigate you simply use the up and down arrow keys (to move up and down a line), space bar (to move down a screen or ‘page’), and ‘q’ to quit.
If you can’t remember how to use the man pages, simply run a man on the man command (as shown below):
These manual pages will be invaluable (combined with some googling!) when scripting, as some queries might require a tweaked version of a command rather then the way you’d normally run it.
–help is typical used after a command (e.g. grep –help) and, in cases where there is a man page, it’ll spit out the entire contents right into the Terminal window (in contrast to man which enters a text viewing program). In some cases this is the only way to view a manual for a command.
The content, much like man, does vary but again, is just as useful. However, note that not all applications have –help or man pages, or have other ways of accessing them.
That’s it for today. I’m hoping this is helpful to those looking to learn how to script, as well as providing a way for you to help yourself! Don’t forget there is always information on Google too.
What are your thoughts? Do you agree with me? Do you have any specific reference webpages to share? Let us know in the comments below and I’ll try to respond to as many as I can.