I would like to modify a i3Blocks script (utility blocks for i3 WM enviroment) that print out the bandwidth in/out .. In particular I would like to change the color of this instruction output:

echo -n " $INLABEL"

using color #9fbc00 how can I do that ? thanks


2 Answers 2


Short answer you can't because true 24 bit colours (rgb) are not part of an accepted standard and it will be a hit or miss whether a terminal supports it or not. You should instead use a predefined colour from the terminal's pallette. ANSI 3/4 bit colours

That being said, some terminals do support true 24bit colours, and most of them use this format: \033[48;2;r;g;bm the 4 in 48 sets the colour as the background, it can be changed to 3 which defines the colour as foreground. (more info)

The r g and b letters represent an 8 bit number in decimal so printf "\033[38;2;159;188;0mhello would print a hello in the colour you wanted (#9fbc00) but it wouldn't reset once the command was executed so you need to tell the terminal to go back to the original colour. To do that, you need to use another escape sequence. \033[0m

Now knowing that, a bug free way to print Hello world! in #9fbc00 would be

printf "\033[38;2;159;188;0mHello world!\033[0m\n".

ps: echo doesn't like escape codes, use printf if you want to format stuff

  • thanks ! this works like a charm in termianal .. unfortunately does not works for i3block script .. in the bar appearance I get all the coloring code !!! but your answer is appropriate since I 've asked for BASH :) Apr 30, 2020 at 19:42
  • @Drudoxlebowsky I haven't used i3 block in a while but [time] color=#ffcc00 command=date '+%A %d-%B %H:%M' interval=5 should be the template (one line per variable) i cant get the format to work in a comment though
    – lor_louis
    Apr 30, 2020 at 19:45
  • yes but this change the colour of the full block and not gust of the label May 1, 2020 at 16:44

Like the man page for i3blocks states:

The standard output of the command line is used to update the block content.  
Each non-empty line of the output will overwrite the corresponding property:

1. full_text

2. short_text

3. color

For example, this script sets the full_text in blue but no short_text:

    echo "Here's my label"
    echo \#0000FF

So have your script print out three lines, the last of them should contain the color code.

This of course changes the color of all your script-output.

  • I'm surprised this isn't the accepted answer - it's exactly what I needed to know when trying to add colors to my i3blocks status bar.
    – Belden
    Nov 14, 2022 at 19:32

You must log in to answer this question.

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