Bash Command Line stderr Error Output Colorize

Colorizing stderr (Error Output) in Bash Command Line

This article introduces how to colorize stderr (error output) in the Bash command line. color()(set -o pipefail;"$@" 2>&1>...

Shou Arisaka
1 min read
Oct 19, 2025

This article introduces how to colorize stderr (error output) in the Bash command line.

color()(set -o pipefail;"$@" 2>&1>&3|sed 

[bash: print stderr in red color - Server Fault](https://serverfault.com/questions/59262/bash-print-stderr-in-red-color)
s,.*,\e[31m&\e[m,'>&2)3>&1

# e.g.
# color sudo apt update

bash: print stderr in red color - Server Fault

This way, define the color() function and colorize with the sed command.

Use colorization in the Bash command line to increase work efficiency.

Thatโ€™s all.

Share this article

Shou Arisaka Oct 19, 2025

๐Ÿ”— Copy Links