Outils du site

Ne dites pas: \"J'ai trouvé la vérité\", mais plutôt: \"J'ai trouvé une vérité\". Ne dites pas: \"J'ai trouvé le chemin de l'âme\". Dites plutôt: \"J'ai rencontré l'âme marchant sur mon chemin\". Car l'âme marche sur tous les chemins.L'âme ne marche pas sur une ligne de crête, pas plus qu'elle ne croit tel un roseau.L'âme se déploie, comme un lotus aux pétales innombrables. [Khalil GIBRAN]

04-linux:20-bash:30-colors

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
04-linux:20-bash:30-colors [2016/10/22 01:51] Roge04-linux:20-bash:30-colors [2017/10/06 23:40] (Version actuelle) – modification externe 127.0.0.1
Ligne 1: Ligne 1:
 +====== Colors ======
  
 +On peut utiliser les couleurs en bash.
 +
 +http://misc.flogisoft.com/bash/tip_colors_and_formatting
 +
 +
 +
 +<code bash>
 +#!/bin/bash
 +
 +#---------------------------------------------------------------------------
 +# Attribute codes:
 +# 00=none 01=bold 02=low 03=Italic 04=underscore 05=blink 07=reverse 08=concealed 
 +# 21=reset bold 22=reset dim 23=reset Italic 24=reset underscore 25=reset blink 27=reset reverse 28=reset hidden 
 +#
 +# Text color codes:
 +# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
 +#
 +# Background color codes:
 +# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
 +#---------------------------------------------------------------------------
 +
 +endColor='\e[0m'
 +reverse='\e[7m'
 +italic='\e[3m'
 +boldItalic='\e[1;3m'
 +bold='\e[1m'
 +black='\e[0;30m'
 +boldBlack='\e[1;30m'
 +red='\e[0;31m'
 +lowRed='\e[2;31m'
 +boldRed='\e[1;31m'
 +green='\e[0;32m'
 +lowGreen='\e[2;32m'
 +boldGreen='\e[1;32m'
 +yellow='\e[0;33m'
 +boldYellow='\e[1;33m'
 +lowYellow='\e[2;33m'
 +blue='\e[0;34m'
 +lowBlue='\e[2;34m'
 +boldBlue='\e[1;34m'
 +magenta='\e[0;35m'
 +boldMagenta='\e[1;35m'
 +cyan='\e[0;36m'
 +boldCyan='\e[1;36m'
 +white='\e[0;37m'
 +lowWhite='\e[2;37m'
 +boldwhite='\e[1;37m'
 +
 +blueOnYellow='\e[0;34;43m'
 +boldBlueOnYellow='\e[1;34;43m'
 +blueOnWhite='\e[0;34;47m'
 +boldBlueOnWhite='\e[1;34;47m'
 +whiteOnBlack='\e[0;37;40m'
 +boldwhiteOnBlack='\e[1;37;40m'
 +blackOnWhite='\e[0;30;47m'
 +boldBlackOnWhite='\e[1;30;47m'
 +boldItalicBlue="\e[1;3;34m"
 +boldDimItalicBlue="\e[1;2;3;34m"
 +boldUnderscoreItalicBlue='\e[1;3;4;34m'
 +
 +function testColor  {
 +    tabs 14
 +    value=$1          # le nom de la variable est passé en paramètre
 +    color=${!value}   # La valeur de la variable
 +    
 +    echo -en "\e[38;5;243m"
 +    echo -n $color # Attention: pas d'option '-e' car elle interprète le '\'
 +    echo -en "${endColor}\t- This is a ${color}${value}${endColor} text."
 +    echo -e "${endColor}"
 +}
 +
 +tput clear # Echo the clear-screen sequence for the current terminal.
 +tput cup 3 10   # Send the sequence to move the cursor to row 3, column 0.
 +echo -e "\n\t\t------ \e[3m\e[7;34m \u2688 \u266b \u2669 \u266a \u266c \u266d \u266e \u266f \u2622 \u26e0 \u23fa  COLORS TEST  \x20\x04 \u23fa ${endColor} ------\n"
 +for i in {124..126} {160..165} {165..160} {126..124} ; do echo -en "\e[48;5;${i}m \e[0m" ; done
 +for i in {16..21} {21..16} ; do echo -en "\e[48;5;${i}m \e[0m" ; done ; echo
 + 
 +testColor black
 +testColor boldBlack
 +
 +testColor lowRed
 +testColor red
 +testColor boldRed
 +
 +testColor lowGreen
 +testColor green
 +testColor boldGreen
 +
 +testColor lowYellow
 +testColor yellow
 +testColor boldYellow
 +
 +testColor lowBlue
 +testColor blue
 +testColor boldBlue
 +
 +testColor magenta
 +testColor boldMagenta
 +
 +testColor cyan
 +testColor boldCyan
 +
 +testColor lowWhite
 +testColor white
 +testColor boldwhite
 +
 +testColor blueOnYellow
 +testColor boldBlueOnYellow
 +
 +testColor blueOnWhite
 +testColor boldBlueOnWhite
 +
 +testColor whiteOnBlack
 +testColor boldwhiteOnBlack
 +
 +testColor blackOnWhite
 +testColor boldBlackOnWhite
 +
 +testColor boldItalicBlue
 +testColor boldDimItalicBlue
 +testColor boldUnderscoreItalicBlue
 +
 +tabs 5 # Set tab spaces
 +echo -e "\n${reverse}${boldItalic} --> 88/256 foreground colors: ${endColor}"
 +#for i in {1..256} ; do echo -en "\e[38;5;${i}m$i\t\e[0m" ; done ; echo
 +for color in {0..256} ; do #Colors
 +    #Display the color
 +    echo -en "\e[38;5;${color}m ${color}\t\e[0m"
 +    #Display 10 colors per lines
 +    if [ $((($color + 1) % 20)) == 0 ] ; then
 +        echo #New line
 +    fi
 +done
 +
 +echo -e "\n\n${reverse}${boldItalic} --> 88/256 background colors: ${endColor}"
 +#for i in {1..256} ; do echo -en "\e[48;5;${i}m $i\e[0m" ; done ; echo -e "${endColor} "
 +for color in {0..256} ; do #Colors
 +    #Display the color
 +    echo -en "\e[48;5;${color}m ${color}\t\e[0m"
 +    #Display 10 colors per lines
 +    if [ $((($color + 1) % 20)) == 0 ] ; then
 +        echo #New line
 +    fi
 +done
 +echo #New line
 +echo #New line
 +</code>