Array of all possible colors in bash script
Sometime back, we had looked at using colors in bash script and here is a way to create a array of all the colors.
#!/bin/bash - #=============================================================================== # # FILE: colorarray.sh # # USAGE: ./colorarray.sh # # DESCRIPTION: # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Amit Agarwal (aka), amit.agarwal@roamware.com # COMPANY: Roamware India Pvt Ltd # CREATED: 16/04/12 17:24:09 IST # Last modified: Mon Apr 16, 2012 05:39PM # REVISION: --- #=============================================================================== count=0 for i in 40m 41m 42m 43m 44m 45m 46m 47m do for l in 0 1 do echo -n "l=$l " for k in 0 1 do # echo -n "k=$k " for j in {30..37} do carr[$count]="\033[$k;$j;$l;$i" echo -ne "${carr[$count]}$count \033[00m" ((count++)) done done echo done echo done
You can add this script to any script of your choice and you have all the 256 colors available to you in the script without additional coding. Happy coding.
Related articles
- colors in bash scripts (amit-agarwal.co.in)
- bash script pass variables to awk script (daniweb.com)
- Fatal error when calling git from bash script in Jenkins (stackoverflow.com)
Related Articles:
- 2012/04/30 colors in bash scripts
- 2010/06/06 colors in bash – script to display all the possible colors.
- 2011/09/16 better bash debugging
- 2011/08/09 bash completion
- 2011/06/11 faster bash operations on files with File Descriptors.
Authored By Amit Agarwal
Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.