Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
04-linux:20-bash:30-colors [2016/10/22 01:22] – Roge | 04-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:// | ||
+ | |||
+ | |||
+ | |||
+ | <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=' | ||
+ | reverse=' | ||
+ | italic=' | ||
+ | boldItalic=' | ||
+ | bold=' | ||
+ | black=' | ||
+ | boldBlack=' | ||
+ | red=' | ||
+ | lowRed=' | ||
+ | boldRed=' | ||
+ | green=' | ||
+ | lowGreen=' | ||
+ | boldGreen=' | ||
+ | yellow=' | ||
+ | boldYellow=' | ||
+ | lowYellow=' | ||
+ | blue=' | ||
+ | lowBlue=' | ||
+ | boldBlue=' | ||
+ | magenta=' | ||
+ | boldMagenta=' | ||
+ | cyan=' | ||
+ | boldCyan=' | ||
+ | white=' | ||
+ | lowWhite=' | ||
+ | boldwhite=' | ||
+ | |||
+ | blueOnYellow=' | ||
+ | boldBlueOnYellow=' | ||
+ | blueOnWhite=' | ||
+ | boldBlueOnWhite=' | ||
+ | whiteOnBlack=' | ||
+ | boldwhiteOnBlack=' | ||
+ | blackOnWhite=' | ||
+ | boldBlackOnWhite=' | ||
+ | boldItalicBlue=" | ||
+ | boldDimItalicBlue=" | ||
+ | boldUnderscoreItalicBlue=' | ||
+ | |||
+ | function testColor | ||
+ | tabs 14 | ||
+ | value=$1 | ||
+ | color=${!value} | ||
+ | | ||
+ | echo -en " | ||
+ | echo -n $color # Attention: pas d' | ||
+ | echo -en " | ||
+ | echo -e " | ||
+ | } | ||
+ | |||
+ | 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 " | ||
+ | for i in {124..126} {160..165} {165..160} {126..124} ; do echo -en " | ||
+ | for i in {16..21} {21..16} ; do echo -en " | ||
+ | |||
+ | 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 " | ||
+ | #for i in {1..256} ; do echo -en " | ||
+ | for color in {0..256} ; do #Colors | ||
+ | #Display the color | ||
+ | echo -en " | ||
+ | #Display 10 colors per lines | ||
+ | if [ $((($color + 1) % 20)) == 0 ] ; then | ||
+ | echo #New line | ||
+ | fi | ||
+ | done | ||
+ | |||
+ | echo -e " | ||
+ | #for i in {1..256} ; do echo -en " | ||
+ | for color in {0..256} ; do #Colors | ||
+ | #Display the color | ||
+ | echo -en " | ||
+ | #Display 10 colors per lines | ||
+ | if [ $((($color + 1) % 20)) == 0 ] ; then | ||
+ | echo #New line | ||
+ | fi | ||
+ | done | ||
+ | echo #New line | ||
+ | echo #New line | ||
+ | </ |