I want to customize my terminal to display emoji faces, showing sad face for wrong command and happy face for right command that I enter. Is there any way that I can do this using my terminal bash.

Here is my PS1 from .bash_profile

export PS1="[\[\e[1;32m\]\@\[\e[m\]] [\[\e[1;34m\]\u\[\e[m\]➡ \[\e[1;31m\]\W\[\e[m\]]\$ "
  • can you define "wrong command" and "right command" -- what exactly should the terminal be trying to do for you? Is a right command any command that process and exits normally? Should this happen as you type in real time? What are you after?
    – samh
    Apr 18, 2019 at 16:58

3 Answers 3


Building on Maghin's post.

# Use echo -n to leave out the line end.
# Use -C option with hexdump to avoid big endian/little 
# endian confusion.
mac $  echo -n 😀 | hexdump -C
00000000  f0 9f 98 80                                       |....|
mac $  echo -n 😱  | hexdump -C
00000000  f0 9f 98 b1                                       |....|

"Include non-0 exit codes in the subsequent bash prompt" http://stackoverflow.com/questions/5946873/include-non-0-exit-codes-in-the-subsequent-bash-prompt

Here is what I ended up with:

export PS1='\u $(highlightExitCode) \$ '

        if [ $exit_code -ne 0 ]
           echo -en '\xf0\x9f\x98\xb1 '
           echo -en '\xf0\x9f\x98\x80 '


enter image description here

A more straight forward alternative for the highlightExitCode function:

 highlightExitCode ()  { 
   if [ $? -ne 0 ]; then
     echo -n '😱 ';
     echo -n '😀 ';

The only problem is that the bad image appears until to you run a succesful command.

enter image description here


You can use the hexadecimal form of the icon.

Here is my method :

Copy an emoji from a graphical source : https://getemoji.com/ Then paste it in your terminal in the following command :

$ echo 😀 | hexdump
0000000 9ff0 8098 000a                         

Then take every octal and put \x before each :

$ echo -e '\xf0\x9f\x98\x80\x0a\x00'
  • This is a helpful start, but is not going to display the proper emoji based on a good or bad command.
    – samh
    Apr 18, 2019 at 16:58
  • You need to know the secret handshake. You need to swap the byte displayed from hexdump. You need to ignore the odd byte & there is no need for the line-end May 8, 2019 at 20:09
  • The correct string is: echo '\xf0\x9f\x98\x80' May 8, 2019 at 20:11
  • Add there is no need for this hex stuff anyway. May 8, 2019 at 20:13

Y'all, why not leave out the UTF-8 byte stuff and just use the Unicode code point value? This stuff is easier to look up on emojipedia and does not nail you down to a single terminal setting.

__ps1_ret() {
  # Don't pollute the return value in case we use it for something else
  local _r=$?
  if ((_r == 0)); then
    echo -n $'\U1F600' # 😀 Grinning Face, U+1F600
    echo -n $'\U1F631' # 😱 Face Screaming in Fear, U+1F631
  return "$_r"


This stuff works everywhere with any encoding that knows how to encode these two characters. Yeah, for emoji this would only include the UTFs and the UTF-in-disguise GB18030 encoding, but it is still a way that more easily connects to well-known sources of emoji reference: code points.

(Oh, the $'...' thing is pretty much restricted to cool shells like bash and zsh.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .