Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

Reading Man Pages

  • Print
  • + Share This
From the author of

From the author of

More Pages to Read

The best way to learn is by doing. Some subjects are best learned with constant, repetitive practice. In this spirit, this section contains a pair of fairly typical man pages broken down and interpreted. If you're sure you know what you're doing, I suggest that you skip to the practice problems in the next section. If you don't do well with those, come back and try these.

echo

ECHO(1)                        FSF                        ECHO(1)

NAME
       echo - display a line of text

SYNOPSIS
       echo [OPTION]... [STRING]...

DESCRIPTION
       Echo the STRING(s) to standard output.

       -n     do not output the trailing newline

       -e     enable interpretation of the backslash-escaped 
              characters listed below

       -E     disable interpretation of those sequences in 
              STRINGs

       -help display this help and exit (should be alone)
       -version
              output version information and exit (should be 
              alone)

       Without -E, the following sequences are recognized and 
       interpolated:

\NNN the character whose ASCII code is NNN (octal)
\\ backslash
\a alert (BEL)
\b backspace
\c suppress trailing newline
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab

REPORTING BUGS
       Report bugs to bug-sh-utils@gnu.org

SEE ALSO
       The full documentation for echo is maintained as a Texinfo 
       manual. If the info and echo programs are properly 
       installed at your site, the command

              info echo

       should give you access to the complete manual.

COPYRIGHT
       Copyright © 1999 Free Software Foundation, Inc.
       This is free software; see the source for copying condi 
       tions. There is NO warranty; not even for MERCHANTABILITY 
       or FITNESS FOR A PARTICULAR PURPOSE.

The header and name sections of this page are self-explanatory. The synopsis, unfortunately, collapses all the options into a single [OPTION]..., which makes it difficult to determine what combinations of options are valid. For example, it's clear, after you read the description, that the -e and -E options are mutually exclusive. Furthermore, it appears that -e is the default, but the description never makes this entirely clear.

The [STRING]... is the line of text to display. A string is geek speak for a line of text. Now try it out:

[ jon@frogbog jon ]$ echo Test Message

Test Message

Yes, it certainly seems to display a line of text. Now try one of the special codes (the man page uses the fancy phrase "backslash-escaped characters," but you know what they mean) listed on the page:

[ jon@frogbog jon ]$ echo Test Message\n

Test Messagen

That didn't work, isn't that strange? The reason is that the shell, the program we are in when we log on to the system and that interprets the command line, converts the backslashes for you. As you would with the echo command, you must escape the backslash, like so:

[ jon@frogbog jon ]$ echo Test Message\\n
Test Message\n

That didn't work either! Perhaps this interpretation of the man page is incorrect, and -E is the default, not -e. Now try that:

[ jon@frogbog jon ]$ echo -e Test Message\\n
Test Message

(If you can't see, there's an extra blank line after the test message.) That worked, despite the system's best efforts to confuse us.

One of the primary reasons people read man pages is to determine the syntax of the command. Although it might be trivial in this example that the page was unclear regarding the defaults, it's often not trivial, and you might well be reduced to this sort of trial-by-error to figure out what the command really does. If the backslash-escape part went by too fast, don't worry; the point here is to learn how to read and use man pages, not to learn everything about Unix at once. This also shows, however, that sometimes what you don't know can interfere with what you do know. Most of the time, however, it doesn't, and you can blithely ignore those things you can't figure out.

  • + Share This
  • 🔖 Save To Your Account