Many scripts work in the background, copying files, handling configuration tasks, and doing other work that is not seen by the user. In other cases, a script must communicate with the user by writing information to the screen. The
echo
command is used to display a message onscreen. All of the text after the
echo
command itself is sent to the Standard Output channel (STDOUT), which normally appears on the screen. The
echo
command is used to give feedback, to inform users
about error conditions, or simply to provide a message of the day. The
echo
command normally ends with a new line. If you use two
echo
commands in succession, each one will print to a
separate line. For example, if these two commands are used in a script:
echo The sample configuration file cannot be found.
echo Please contact your vendor for information.
The result that appears on screen will look like this:
The sample configuration file cannot be found.
Please contact your vendor for information.
On some UNIX platforms the
echo
command can include the
-n
parameter to prevent the new line at the end of the text. For example, if these two commands are used in a script:
echo –n Contact your agent about the following file:
echo /etc/smb.conf
The result that appears on screen will look like this:
Contact your agent about the following file:
/etc/smb.conf