About
This page is about the echo executable of the Gnu utility package that implements an echo functionality.
echo is also often implemented as a shell built-in command:
Articles Related
Syntax
To echo a string:
/bin/echo [OPTION]... [STRING]...
where:
- -n: do not output a newline character. See the example below trailing_newline
- -e: enable interpretation of backslash_escapes
- -E: disable interpretation of backslash_escapes (default)
- –help display this help and exit
- –version: output version information and exit
backslash escapes
If -e is in effect, the following sequences are recognized:
- \0NNN the character whose ASCII code is NNN (octal)
- \\ backslash
- \a alert (BEL)
- \b backspace
- \c suppress trailing newline
- \f form feed
- \n new line
- \r carriage return
- \t horizontal tab
- \v vertical tab
This characters are control characters.
See the example interpretation of non visible characters
Location
The echo utility is found:
- on linux at /bin/echo
- on windows: installed with Git - Git (executable|command line) at Git_Home\usr\bin\echo.exe
Management
Check if this is the gnu echo
In bash, with the type command, you can check if it's the echo bash builtin command and not GNU echo.
type echo
echo is a shell builtin
Example
Interpretation of non visible (\) characters
- with the e option and with the double quoted string
echo -e "hello Nico\nHello Nico"!
hello Nico
Hello Nico!
- without the e options and with single quoted string
echo 'hello Nico\nHello Nico!'
hello Nico
Hello Nico!
trailing newline
By default, echo outputs along a newline character at the end. This behavior can be disabled with the -n options
Example within the bash shell:
- with -n, no newline character will be added and the sequence of number will be on one line
for a in `seq 10`
do
echo -n "$a "
done
1 2 3 4 5 6 7 8 9 10
- without -n (default), a newline character will be added and the sequence of number will be on multiple line
for a in `seq 10`
do
echo "$a "
done
1
2
3
4
5
6
7
8
9
10