Interacting with the User

The following section further demonstrates some of the script commands discussed earlier in this chapter and adds some new ones to your skill set.

Displaying Headings and Prompts

The echo command just displays the argument words it has been given. As such, it is rarely used at the command line. However, it is very useful in shell scripts. Its simplest use is to provide a heading for your output:

#!/bin/sh
echo "Users currently logged in at `date`"
who

In this example, the echo command outputs a heading before the output of the who command is shown. The heading uses backquotes so that the current date and time are inserted into the heading.

The echo command allows for the following formatting escape characters that ...

Get Practical UNIX now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.