background effect
Foreground
Foreground
D0Z - motion / graphic / dev๐Ÿงบ
Difference Between echo and echo -eโœ•

brain

Some files are private or not ready yet, if a link gives you a 404 that's why :)
This is a work in progress, new notes will be added daily

List of note Indexes

    
                .... |\| .|||.    |\/|  .|\\. .|.
              .\\||/|.  .\|..||  .\|..|||...||.....
            .|   .....||.|\\\\\\    ... |\\\/. .\\. .||
        .\\|   .|\\|..|\\ .\\\\  .\\|. .\\\\\|  |\| |\\|
        |\\  |\\|..  /\\\. |\|\\   \\\\|.   .|\\. .\\\\|
        .\\. |\\\\\\\|.. .\\|      .\\||\\/|. |\\|     .|/\|
      \. .\\\||/\|....   \\| |\/   |\\\  |\\\| .\\|  \\| ....
    |\/  |\\| |\\\\\\\| |\|.\\\   \\\\. |\\\\| |\\  \\.  ||..
      ..|||\|  .. .\\\\. |\\\\\\  .\\|....|\\\. |\\\\\\  |/. |/
    \\\|..   .\\\ |\\. .\\\| \\|   |||\\\.  ...|\\/||.  .\\\
  |\|  |\/.  /\\\\\| .\\\\. \\.   .../|.   .|\\\|.   |\\\|  |\\
    .  |||\\|.  ..||| .\\|.  |\|  \\|..../\\| |\\|  .\\\\\   ..
    \\|  .||\|.|..      |\\\|./\  \\||\. ||...    .\\\\/.  |\/||
    ..|/||.   |\\\\\|.     .|/\|  ||.        .||\\\     .|||. |\
  .\/|  \\\. .|\\\|||\\\||..       .|\\\\\\\|\\\\.  /\\\\||. |
    .|| |\\\\|  .......|\\\\\\.  .\\\. ..|||....  .\\\\|.. ...
    \\||....|\\\\\\\\||\\\\\\\/   |\|....|||\\\\\\\/....|\\\|
      ||.|\||\\| .....|\\\\..\\|    .|\\\. ||........ .|\|...
          . |\  /\\/\\\\\\. |\.  .\\\\\\.  ./\\\\/  |\\\||.
        .|\.|\| .|\|... ..              ./\\|..|\\|  ..
            .|\\|  .\\\\.\\\\\\\   \||...\\\|..|\\\|.||
                |\. ..||....||     ... ..||\\\. .|.
                        ...            .......

  

โ†‘ ๐Ÿ”’ Bash


Difference Between echo and echo -e

The main difference between echo and echo -e is how they handle backslash escape sequences in the output.

Standard echo (without -e)

  • Behavior: Treats backslashes and special characters literally

  • Example:

    echo "Hello\nWorld"
    bash

    Output:

    Hello\nWorld
    text

echo -e (with escape interpretation)

  • Behavior: Interprets backslash escape sequences

  • Example:

    echo -e "Hello\nWorld"
    bash

    Output:

    Hello
    World
    text

Common Escape Sequences

Here are escape sequences that echo -e interprets:

SequenceMeaningExample
\nNew lineecho -e "Line1\nLine2"
\tTabecho -e "Name\tAge"
\\Backslashecho -e "Path\\to\\file"
\bBackspaceecho -e "Hello\bWorld"
\rCarriage returnecho -e "Overwrite\rNew"
\aAlert (bell)echo -e "\a"
\eEscape characterecho -e "\e[31mRed\e[0m"

Portability Considerations

  • The -e option is not POSIX compliant

  • For portable scripts, use printf instead:

    printf "Hello\nWorld\n"
    bash
  • Different shells (bash, dash, zsh) may handle echo differently

Practical Examples

  1. Creating formatted output:

    echo -e "Column1\tColumn2\tColumn3"
    bash
  2. Multi-line messages:

    echo -e "First line\nSecond line\nThird line"
    bash
  3. Colored output:

    echo -e "\e[31mError:\e[0m File not found"
    bash
  4. Progress indicators:

    echo -e "Processing...\rDone!     "
    bash

Best Practices

  1. For simple output without escapes, use plain echo
  2. For complex formatting with escapes, use either:
    • echo -e (bash-specific)
    • printf (more portable)
  3. When writing scripts for multiple systems, prefer printf
ยฉ 2026 d0z.eu | 0.1.0-beta.41