Writing Output but Preserving Spacing

Problem

You want the output to preserve your spacing.

Solution

Enclose the string in quotes. The previous example, but with quotes added, will preserve our spacing.

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

or:

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

Discussion

Since the words are enclosed in quotes, they form a single argument to the echo command. That argument is a string and the shell doesn’t need to interfere with the contents of the string. In fact, by using the single quotes ('') the shell is told explicitly not to interfere with the string at all. If you use double quotes (“), some shell substitutions will take place (variable and tilde expansions and command substitutions), but since we have none in this example, the shell has nothing to change. When in doubt, use the single quotes.

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.223.195.29