Shell Data Processing - Echo (Gnu Utility)

1 - 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:

3 - 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

3.1 - 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

3.1.1 - Location

The echo utility is found:

4 - Management

4.1 - 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

5 - Example

5.1 - Interpretation of non visible (''\'') characters

See Text - Control 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!

5.2 - 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


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap