You are not logged in.

#1 2015-03-07 15:36:46

Painless
Member
Registered: 2006-02-06
Posts: 234

bash_256_colours.sh

A bash script for displaying the available 256 term colours.  I'm working on a script which requires coloured output, and different terms display colours differently, so I need the colours for a reference.  This is not the first, and won't be the last such script, but I wanted something that displayed the colours in a coherent manner.  I saw the same output done using ruby and thought it was good.  I decided to write something short and simple in bash, mostly as an exercise.

#!/bin/bash
#
for i in $(seq -f %03g 0 255)
do
  j=$(echo $i | sed 's/^0*//')
  printf "\e[48;5;${i}m\e[38;5;15m ${i} "
  printf "\e[48;5;0m\e[38;5;${i}m ${i} "
  case "$i" in
    "007") printf "\n" ;;
    "015") printf "\n" ;;
  esac
  if [[ $j -ge 21 && $(( (${j}-15) % 6 )) -eq 0 ]]
  then
    printf "\n"
  fi
done

Typical output:
bash_256_colours-thumb.jpg

I hope it's useful.  smile

Offline

#2 2015-03-07 16:57:41

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,746
Website

Re: bash_256_colours.sh

Very nice -- thank you!


Para todos todo, para nosotros nada

Offline

#3 2015-03-07 20:50:45

ninian
Member
From: United Kingdom
Registered: 2008-02-24
Posts: 726
Website

Re: bash_256_colours.sh

Painless wrote:

I hope it's useful.  smile

Yes indeed, and appreciated, thanks.
smile

Offline

Board footer

Powered by FluxBB