Writing Output to the Terminal/Window

Problem

You want some simple output from your shell commands.

Solution

Use the echo built-in command. All the parameters on the command line are printed to the screen. For example:

echo Please wait.

produces

Please wait.

as we see in this simple session where we typed the command at the bash prompt (the $ character):

$ echo Please wait.
Please wait.
$

Discussion

The echo command is one of the most simple of all bash commands. It prints the arguments of the command line to the screen. But there are a few points to keep in mind. First, the shell is parsing the arguments on the echo command line (like it does for every other command line). This means that it does all its substitutions, wildcard matching, and other things before handing the arguments off to the echo command. Second, since they are parsed as arguments, the spacing between arguments is ignored. For example:

$ echo this    was     very    widely    spaced
this was very widely spaced
$

Normally the fact that the shell is very forgiving about white space between arguments is a helpful feature. Here, with echo, it’s a bit disconcerting.

See Also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.208.183