Outils pour utilisateurs

Outils du site


informatique:linux:printf

Différences

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

Lien vers cette vue comparative

Prochaine révision
Révision précédente
informatique:linux:printf [2008/02/20 15:02] – créée benoitinformatique:linux:printf [2008/02/20 15:50] (Version actuelle) – benoit
Ligne 1: Ligne 1:
 ====== printf ====== ====== printf ======
  
-Pour afficher par exemple hello en couleur :+**Syntax:**
  
-rouge :+1ere chaine en gras, code couleur, deuxième texte : '\033[**31**m**hello**\033[m\n' 
 + 
 +=== Pour afficher par exemple hello en couleur :=== 
 + 
 +**rouge :** 
 +  printf '\033[31mhello\033[m\n' "hello" 
 +ou
   printf '\033[%sm%s\033[m\n' "31" "hello"   printf '\033[%sm%s\033[m\n' "31" "hello"
  
-vert :+ 
 + 
 +**vert :**
   printf '\033[%sm%s\033[m\n' "32" "hello"   printf '\033[%sm%s\033[m\n' "32" "hello"
  
-jaune :+**jaune :**
   printf '\033[%sm%s\033[m\n' "33" "hello"   printf '\033[%sm%s\033[m\n' "33" "hello"
  
-bleu foncé :+**bleu foncé :**
   printf '\033[%sm%s\033[m\n' "34" "hello"   printf '\033[%sm%s\033[m\n' "34" "hello"
  
-violet :+**violet :**
   printf '\033[%sm%s\033[m\n' "35" "hello"   printf '\033[%sm%s\033[m\n' "35" "hello"
  
-bleu ciel :+**bleu ciel :**
   printf '\033[%sm%s\033[m\n' "36" "hello"   printf '\033[%sm%s\033[m\n' "36" "hello"
  
-gris :+**gris :**
   printf '\033[%sm%s\033[m\n' "37" "hello"   printf '\033[%sm%s\033[m\n' "37" "hello"
  
  
-surligné rouge :+**surligné rouge :**
   printf '\033[%sm%s\033[m\n' "41" "hello"   printf '\033[%sm%s\033[m\n' "41" "hello"
  
-surligné vert :+**surligné vert :**
   printf '\033[%sm%s\033[m\n' "42" "hello"   printf '\033[%sm%s\033[m\n' "42" "hello"
  
-surligné jaune :+**surligné jaune :**
   printf '\033[%sm%s\033[m\n' "43" "hello"   printf '\033[%sm%s\033[m\n' "43" "hello"
  
-surligné bleu foncé :+**surligné bleu foncé :**
   printf '\033[%sm%s\033[m\n' "44" "hello"   printf '\033[%sm%s\033[m\n' "44" "hello"
  
-surligné violet :+**surligné violet :**
   printf '\033[%sm%s\033[m\n' "45" "hello"   printf '\033[%sm%s\033[m\n' "45" "hello"
  
-surligné bleu ciel :+**surligné bleu ciel :**
   printf '\033[%sm%s\033[m\n' "46" "hello"   printf '\033[%sm%s\033[m\n' "46" "hello"
  
-surligné gris :+**surligné gris :**
   printf '\033[%sm%s\033[m\n' "47" "hello"   printf '\033[%sm%s\033[m\n' "47" "hello"
 +
 +=== intégrer la couleur à un script shell ===
 +
 +Il suffit de créer la fonction suivante dans le script :
 +  color()
 +  {
 +    #Fonction pour afficher les echo en couleur
 +    #31=rouge, 32=vert, 33=jaune,34=bleu, 35=rose, 36=cyan, 37= blanc
 +    printf '\033[%sm%s\033[m\n' "$@"
 +  }
 +
 +et de l'appeler dans la script par la commande :
 +  color 32 "hello"
 +
 +ou pour mettre en évidence une erreur ou un succès en faisant apparaitre OK ou NOK en couleur :
 +  echo "TEST TRUC MUCHE : $(color 32 OK)"
 +  echo "TEST TRUC MUCHE : $(color 31 NOK)"
informatique/linux/printf.1203519753.txt.gz · Dernière modification : (modification externe)