Shell Data Processing - Echo (Gnu Utility)

Card Puncher Data Processing

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:

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:

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

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!

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





Discover More
Bash Liste Des Attaques Ovh
Bash - Echo (Bultin Command)

Echo in bash. Echo accepts an argument (a literal string or a variable) as standard input, and echoes it back to the terminal as standard output. In Bash, it's available as: the builtin bash command...
Card Puncher Data Processing
Shell Data Processing - (WC|Word Count) command (Line count)

The wc command is a filter that prints on one line sequentially the number of: newlines (lines), words, and characters from: files or from an input stream when: no FILE is specified or...



Share this page:
Follow us:
Task Runner