Many people assume the shell command echo can output anything, including pictures, but it only writes text to standard output. The accurate answer is that echo cannot directly display an image; you need a dedicated image viewer or a terminal that understands graphic escape sequences.
Quick answer: echo prints text only; use an image viewer or a terminal‑image protocol to show pictures.
Echo’s purpose and limitations
The echo command is designed to write strings of characters to the console, a file, or a pipe. It treats its arguments as plain text, adds a newline by default, and performs minimal interpretation of escape sequences. Because it works with character data, any binary bytes that make up a picture are interpreted as unreadable glyphs or cause the terminal to misbehave.
When you try echo < picture.png, the shell expands < as a redirection operator, not as part of the command, and the binary data never reaches echo. Even if you force binary data into echo with echo -e "\x89PNG...", the terminal will still show garbled characters because it does not know how to render the PNG format. In short, echo is a text‑only tool and not a graphics engine.
Why text commands can’t render raster graphics
Raster images consist of millions of bytes that describe pixel colors, compression headers, and metadata. Rendering those bytes requires a decoder that understands formats like PNG, JPEG, or GIF and then maps the pixel data onto a screen buffer. The shell and its built‑in commands have no such decoder; they simply pass bytes through.
Terminals historically display only characters from a fixed glyph set. Modern terminals can display Unicode, but they still rely on the font rasterizer, not on image decoding. Therefore, without a specialized protocol, a terminal cannot turn raw image bytes into visible pictures, and echo cannot bridge that gap.
Standard Linux tools that actually display images
If you need to view an image from the command line, tools like display (from ImageMagick), feh, eog (Eye of GNOME), or xdg-open will launch a graphical viewer that knows how to decode the file. For example, display picture.jpg opens a window that shows the picture exactly as intended.
These programs accept a filename as an argument, locate the appropriate decoder, and render the image in a separate window. They can also be called from scripts, allowing automation without trying to misuse echo. When a graphical environment is unavailable, you can fall back to a framebuffer viewer like fbi or fim that writes directly to the console’s video memory.
How to show an image in a terminal that supports graphics
Some modern terminal emulators, such as iTerm2 on macOS or Kitty on Linux, understand proprietary escape sequences that embed bitmap data directly into the terminal buffer. To use these, you typically pipe the image through a helper like catimg or kitten graphics. For Kitty, the command looks like kitty +kitten icat picture.png, which renders the picture inline.
These terminals handle the decoding internally, so you never need echo at all. The workflow is: ensure your terminal supports the protocol, install the helper utility, and then run the helper with the image filename. If you are using iTerm2, the built‑in imgcat script works similarly: imgcat picture.png.
Converting an image to ASCII art for pure‑text output
When you truly need to stay within plain text, the common workaround is to convert the picture to ASCII art. Tools like jp2a, caca-utils (specifically img2txt), or asciiview read the image, map brightness to characters, and output a text representation.
For example, jp2a --width=80 picture.jpg prints an 80‑character‑wide ASCII version that any terminal can display. The result is still text, so echo can be used to forward it, but the heavy lifting is done by the conversion tool, not by echo itself.
Common pitfalls when trying to pipe binary data with echo
Attempting to pipe binary data through echo often truncates the stream because echo stops at the first null byte (\0). Many image formats start with a null byte or contain them later, causing the output to be incomplete. Additionally, some shells interpret backslashes as escape characters, altering the binary content unintentionally.
Another issue is line‑ending conversion. If you run echo in a Windows‑compatible environment, it may add carriage return characters (\r\n) that corrupt the image file. The safest way to handle raw binary data is to use cat or dd, which copy bytes verbatim without interpretation.
Putting it together: a practical workflow for showing images from a script
Suppose you have a Bash script that needs to display a picture to the user. First, detect whether the environment supports inline graphics. You can check the $TERM_PROGRAM variable for "iTerm.app" or the $KITTY_WINDOW_ID variable for Kitty. If a supported terminal is found, call the appropriate helper (e.g., imgcat or kitty +kitten icat) with the image path.
If no graphic‑capable terminal is detected, fall back to launching a graphical viewer with xdg-open on Linux or open on macOS. As a last resort, convert the image to ASCII using jp2a and pipe the result to cat for display. This layered approach avoids the temptation to misuse echo and ensures the image is shown correctly in the widest range of environments.
Rule of thumb to remember
Whenever you think about showing a picture from the command line, remember: echo = text only; use a viewer, a terminal‑image protocol, or an ASCII converter for graphics.
By keeping this rule in mind, you avoid wasted attempts with echo and choose the right tool for the job, whether that is a GUI program, a terminal helper, or an ASCII art generator.