Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to change the font attributes of the output of echo in either zsh or bash?

What I would like is something akin to:

echo -n "This is the font: normal "
echo -n $font=italic "italic,"
echo -n $font=bold "bold,"
echo -n "and"
echo -n $font=small "small".

so that it print: "This is the font: normal, italic, bold, small" within a line of text.

share|improve this question
This has more to do with the terminal emulator in question than with the used shell. This question thread contains some valuable pointers, I think – sr_ Apr 25 '12 at 8:33
Normally, you cannot change the font size. The only thing, you usually can do, is changing color and sometimes the bold/underlined attribute. For this, you can use ANSI escape sequences. See e.g. bashguru.com/2010/01/shell-colors-colorizing-shell-scripts.html for some examples. – jofel Apr 25 '12 at 8:35
up vote 10 down vote accepted

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
echo $bold_color$fg[red]bold red${reset_color}plain$'\e'$color[underline]munderlined
share|improve this answer

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



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.

share|improve this answer
+1: exactly what I needed ! – Stephane Rolland Feb 7 '13 at 23:47

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:

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.

share|improve this answer
Escape characters can be typed: Ctrl+V, Esc. (Will be displayed as “^[”. This mean the whole ANSI sequence will look like “^[[1mbold”.) – manatwork Apr 25 '12 at 11:49
There are more attributes to mention: \e[4m underlined, \e[5m blinking, \e[7m inverted. – manatwork Apr 25 '12 at 11:52
@manatwork: added them. – user unknown Apr 25 '12 at 12:04



(note: a lot of them usually don't work, but most of these are marked thus.)

I'm making a game in the terminal and have been relying heavily on the above link. It even tells you how to hide/unhide the cursor, make color (30's), "bold" (lighter), darker, underlined, italic, background color (40's instead of 30's), etc. You can also change the cursor's location (which is very helpful - for example, "\x1B[1A" moves the cursor up one line; "\x1B[0;0H" moves the cursor to row 0, col 0; "\x1B[2J" clears the screen; "\x1B[2K" clears the line.

For your purposes as people have said:

echo -e "\x1b[30;44m black with blue background \x1b[m"

echo -e "\x1b[31;42m red with green background \x1b[m"

echo -e "\x1b[32;40m green with black background \x1b[m"

echo -e "\x1b[8m Invisible; na na na na boo boo \x1b[m"

Note: You need the -e in

echo **-e** "\x1b[35;1m Light purple \x1b[m"

or you need to use single quotes. Type man echo to see why (double quotes are usually a pain when printing; when I need stuff to not expand or I need ANSI escape sequences, I use single quotes because it is easy - even though I gotten used to it from doing it so many times - to forget the -e in which case you get "box with numbers and letters[35;1m").

Every time you see CSI replace it with "\x1b[" (or "\e[" or "\u1b["). "\x1b[" I think is more standard, but I don't really know what the difference is between them is.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.