Echo

From LQWiki
Jump to: navigation, search

echo is a shell command which prints data to the screen (well, stdout actually). (You may recognize it from some programming languages - Perl and PHP both use it)

For example:

$ echo Hello World
Hello World
$

If run in the context of a shell script, then you can allow echo to print the contents of variables by prefixing the variable name with a dollar sign. For example:

$ x=`date`
$ echo $x
Sat Aug 7 12:57:04 UTC 2004
$ 

It is also possible to output ASCII data. The syntax is

echo -e "\0NNN"

where NNN is the ascii number in octal format. To output an A (ascii code 65), use

echo -e "\0101"

To output all ASCII charaters, use

for l in $(seq 0 1 7); do for i in $(seq 0 1 7); do for n in $(seq 0 1 7); do \
echo -en "\0${l}${i}${n}  ";done;  done;done 

Provided by

Most shells provide this as a builtin, but this is also present in the GNU Coreutils as a utility. The two forms may have different behavior. Most (all?) Linux distributions incorporate the utility from the GNU Coreutils: man page

Tips

  1. Because of behavior differences, you are usually best off to decide on one of the forms and always use that form. Life is less confusing that way.

Related Commands

See also