/bin/echo Hello, world!
In the above command, the two words (Hello, and world!) are passed to echo as separate arguments, and echo prints them in sequence, separated by a space:
Hello, world!
The next command produces the same output:
/bin/echo 'Hello, World!'
Hello, world!
However, unlike the first example, the above command provides the single-quoted string 'Hello, world!' as a single argument.
Single-quoting a string will reliably protect it from interpretation by the shell, passing special characters and escape sequences literally to echo.
For instance, in the bash shell, variable names are preceded by a dollar sign ($). In the next command, the variable name inside the quotes is treated literally; outside the quotes, it is converted to its value.
/bin/echo 'The value of $PATH is' $PATH
The value of $PATH is /home/hope/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Escape sequences are not interpreted, by default:
/bin/echo 'Here, \bthe \bbackspace \bsequences \bare \bignored.'
Here, \bthe \bbackspace \bsequences \bare \bignored.
However, if you provide the -e option, they will be interpreted:
/bin/echo -e 'Here, \bhowever, \bthe \bbackspace \bsequences \bare \binterpreted.'
Here,however,thebackspacesequencesareinterpreted.
If you need to insert newlines in your echo output, specify the -e option and include the \n escape sequence wherever you want a new line:
echo -e 'Here,\nwe\nhave\ninserted\nnewlines.'
Here,
we
have
inserted
newlines.
Same for tabs:
echo -e 'Here\twe\thave\tinserted\thorizontal\ttabs.'
Here we have inserted horizontal tabs.
Another example:
echo -e 'This line is not completely \cprinted.'
This line is not completely