Show numerical values for each of the 256 colors in bash

for code in {0..255}; do echo -e "\e[38;05;${code}m $code: Test"; done
Same as http://www.commandlinefu.com/commands/view/5876, but for bash. This will show a numerical value for each of the 256 colors in bash. Everything in the command is a bash builtin, so it should run on any platform where bash is installed. Prints one color per line. If someone is interested in formatting the output, paste the alternative.

45
By: scribe
2010-06-19 02:14:42

4 Alternatives + Submit Alt

What Others Think

hmm, needs to set a background color so it doesn't blend in so badly with my shell's bg color.
kaedenn · 431 weeks and 1 day ago
I'd echo the code itself rather than "Test". See http://www.pixelbeat.org/scripts/ansi_colours.sh For a 256 color palette you can hover over to get the code see: http://www.pixelbeat.org/docs/terminal_colours/#256
pixelbeat · 430 weeks and 6 days ago
More compact output all on one line: for code in {0..255}; do echo -en "\e[38;05;${code}m $code:"; done
dattaway · 430 weeks and 5 days ago
The pretty part of the table, nicely formatted: for line in {0..5}; do for col in {0..39}; do code=$(( $col * 6 + $line + 16 )); printf $'\e[38;05;%dm %03d' $code $code ;done; echo ;done
bartonski · 428 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: