Change font in echo command

On most if not all terminal emulators, you can't set different font sizes or different fonts, only colors and a few attributes (bold, underlined, standout).

In bash (or in zsh or any other shell), you can use the terminal escape sequences directly (apart from a few exotic ones, all terminals follow xterm's lead these days). CSI is ESC [, written $'\e[' in bash. The escape sequence to change attributes is CSI Ps m.

echo $'\e[32;1mbold red\e[0mplain\e[4munderlined'

Zsh has a convenient function for that.

autoload -U colors
colors
echo $bold_color$fg[red]bold red${reset_color}plain$'\e'$color[underline]munderlined

Or can do it as part of prompt expansion, also done with print -P, or the % parameter expansion flag:

print -P '%F{red}%Bbold%b red%f %Uunderline%u'

You could include these color definitions in a script or source file. Could look something like this.

#!/bin/bash
PATH=/bin:/usr/bin:

NONE='\033[00m'
RED='\033[01;31m'
GREEN='\033[01;32m'
YELLOW='\033[01;33m'
PURPLE='\033[01;35m'
CYAN='\033[01;36m'
WHITE='\033[01;37m'
BOLD='\033[1m'
UNDERLINE='\033[4m'

echo -e "This text is ${RED}red${NONE} and ${GREEN}green${NONE} and ${BOLD}bold${NONE} and ${UNDERLINE}underlined${NONE}."

tput sgr0

Notice that you should reset the ANSI color codes after each instance you invoke a change. The tput sgr0 resets all changes you have made in the terminal.

I believe changing the font size or italics would be specific to the terminal you are using.

While this guide is specific to customizing your bash prompt, it is a good reference for color codes and generates some ideas of what you can do.


Seems as if the layout can't handle the [0x1b]-character in front of the [.

The first line makes bold:

 echo -e "\x1b[1m bold"
     echo -e "\x1b[30m black"
     echo -e "\x1b[31m red"
     echo -e "\x1b[32m green"
     echo -e "\x1b[33m yellow"
     echo -e "\x1b[34m blue"
     echo -e "\x1b[35m mag"
     echo -e "\x1b[36m cyan"
     echo -e "\x1b[37m white"   

For the general type, I only know

echo -e "\x1b[0m io-std"
echo -e "\x1b[1m bold"
echo -e "\x1b[2m normal"

and from the comments, thanks manatwork and GypsyCosmonaut:

echo -e "\x1b[3m italic"
echo -e "\x1b[4m underlined"
echo -e "\x1b[5m blinking"
echo -e "\x1b[7m inverted"

and don't know the difference between io-std and normal.

I haven't seen italic or small in the shell.

You can enter them (thanks to manatwork too) by Ctrl + v ESC in the Bash, where it will be displayed as ^[. This mean the whole ANSI sequence will look like ^[[1m bold or ^[[1mbold (to avoid the blank before 'bold').

Many editors have problems with (char)0x1b. Alternatives: copy/paste it from somewhere, or use

echo -e "\x1b[1m bold"

in bash, or a hex editor.

Or, even simpler:

echo -e "\e[1m bold"

The \e is an escape sequence for the ascii code 27, for the bash internal command echo as well as for the external program GNU-echo.