# Variable du shell dans un script

**URL:** <https://www.debian-fr.org/t/variable-du-shell-dans-un-script/88807>\
**Category:** Programmation\
**Created:** [Septembre 17, 2023, 10:15 UTC](https://www.debian-fr.org/t/variable-du-shell-dans-un-script/88807 "2023-09-17T10:15:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![josephtux](https://www.debian-fr.org/user_avatar/www.debian-fr.org/josephtux/32/3985_2.png) [@josephtux](https://www.debian-fr.org/u/josephtux)\
**Post date:** [Septembre 17, 2023, 10:15 UTC](https://www.debian-fr.org/t/variable-du-shell-dans-un-script/88807/1 "2023-09-17T10:15:58Z")

</div>

Bonjour,

_man grep_ indique que la variable GREP\_COLORS contient le code couleur utilisé par _grep_.

Je veux modifier cette couleur localement dans un script, et j’ai tenté ceci:

```
#!/bin/bash --
...
Colorinit="$GREP_COLORS"
GREP_COLORS='\e[;40;32;1m'
mount | grep --color=auto seagateUSB4T\[_-\]... || echo "Erreur: ..."
GREP_COLORS="$Colorinit"
...

```

Mais je constate que la variable $GREP\_COLORS n’est pas importée dans le script, et que sa nouvelle valeur (vert au lieu de rouge) n’est pas non plus prise en compte.

PS  
en réalité j’ai écrit:

> GREP\_COLORS=«&nbsp;$vert&nbsp;»

La variable «vert» contenant la chaine «\e[;40;32;1m» , importée d’une bibliothèque personnelle de codes couleurs utilisée couramment sans problème:

```
# 1 FOND NOIR:
  rose='\e[;40;31m'
 rouge='\e[;40;31;1m'
 vertm='\e[;40;32m'
  vert='\e[;40;32;1m'
 jaune='\e[;40;33;1m'
...

```

Pour en vérifier la syntaxe, je ne sais d’ailleurs pas comment l’afficher en ligne de commande:  
`echo "$GREP_COLORS"`  
affiche une ligne vide.

---

<div class="post-metadata">

**Author:** ![anon29980398](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@anon29980398](https://www.debian-fr.org/u/anon29980398)\
**Post date:** [Septembre 17, 2023, 10:29 UTC](https://www.debian-fr.org/t/variable-du-shell-dans-un-script/88807/2 "2023-09-17T10:29:15Z")

</div>

Bonjour

> [@josephtux](#):
>
> la variable GREP\_COLORS contient le code couleur utilisé par _grep_

Il y a un **S** à GREP\_COLOR **S** =\> plusieurs couleurs, et chacune en fonction d’un contexte défini.

* * *

Un peu de lecture : [gnu.org → grep → 2.2 Environment Variables](https://www.gnu.org/software/grep/manual/html_node/Environment-Variables.html)

---

<div class="post-metadata">

**Author:** ![josephtux](https://www.debian-fr.org/user_avatar/www.debian-fr.org/josephtux/32/3985_2.png) [@josephtux](https://www.debian-fr.org/u/josephtux)\
**Post date:** [Septembre 17, 2023, 10:33 UTC](https://www.debian-fr.org/t/variable-du-shell-dans-un-script/88807/3 "2023-09-17T10:33:37Z")

</div>

Grand merci MicP pour cette remarque et ce lien.

---

<div class="post-metadata">

**Author:** ![josephtux](https://www.debian-fr.org/user_avatar/www.debian-fr.org/josephtux/32/3985_2.png) [@josephtux](https://www.debian-fr.org/u/josephtux)\
**Post date:** [Septembre 17, 2023, 11:07 UTC](https://www.debian-fr.org/t/variable-du-shell-dans-un-script/88807/4 "2023-09-17T11:07:29Z")

</div>

Ce lien indique:

> Instead of `GREP_COLOR='color'`, you can use `GREP_COLORS='mt=color'`.

j’ai donc tenté:

```plaintext
GREP_COLORS='mt=01;32'

```

puis :

```plaintext
declare -A GREP_COLORS='mt=01;32'

```

de même avec:

```plaintext
GREP_COLORS='\033[32m'

```

mais en vain.

---

<div class="post-metadata">

**Author:** ![anon29980398](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@anon29980398](https://www.debian-fr.org/u/anon29980398)\
**Post date:** [Septembre 17, 2023, 1:51 UTC](https://www.debian-fr.org/t/variable-du-shell-dans-un-script/88807/5 "2023-09-17T13:51:10Z")

</div>

![Capture d’écran_2023-09-17_16-03-52](https://www.debian-fr.org/uploads/default/original/2X/5/53c7d59dc7a8373c433fc5d2b8a08121c03acf99.jpeg)

---

<div class="post-metadata">

**Author:** ![josephtux](https://www.debian-fr.org/user_avatar/www.debian-fr.org/josephtux/32/3985_2.png) [@josephtux](https://www.debian-fr.org/u/josephtux)\
**Post date:** [Septembre 18, 2023, 8:56 UTC](https://www.debian-fr.org/t/variable-du-shell-dans-un-script/88807/6 "2023-09-18T08:56:59Z")

</div>

Encore merci MicP
