# Bash : Variables, comment les utiliser en dehors du fichier ?

**URL:** <https://www.debian-fr.org/t/bash-variables-comment-les-utiliser-en-dehors-du-fichier/74746>\
**Category:** Programmation\
**Created:** [Octobre 13, 2017, 1:21 UTC](https://www.debian-fr.org/t/bash-variables-comment-les-utiliser-en-dehors-du-fichier/74746 "2017-10-13T13:21:41Z")\
**Posts on this page:** 1\
**Showing post:** 6

<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:** [Octobre 13, 2017, 2:13 UTC](https://www.debian-fr.org/t/bash-variables-comment-les-utiliser-en-dehors-du-fichier/74746/6 "2017-10-13T14:13:08Z")

</div>

Bonjour

Si le shell est **bash**

Extrait de la page man de **bash**  
option **a** de la commande interne **set** du **bash** :

```nohighlight
…
     -a Marquer automatiquement des variables et fonctions modifiées ou créées 
         pour qu'elles soient exportées dans l'environnement des commandes exécutées ultérieurement.
…

```

* * *

Donc :

```nohighlight
set -a
source mes_variables.txt
set +a

```

* * *

La commande **source** peut être remplacée par un simple point  
donc, en une seule ligne, on pourrait écrire :

```
set -a;. mes_variables.txt;set +a

```

Ce qui donnerait :

```
michel@debg53sw:~$ cat mes_variables.txt
animal="chat"
couleur="gris"
prenom="grigri"
michel@debg53sw:~$ echo $animal $couleur $prenom

michel@debg53sw:~$ set -a;. mes_variables.txt;set +a
michel@debg53sw:~$ echo $animal $couleur $prenom
chat gris grigri
michel@debg53sw:~$ 

```

* * *

Voir : [https://unix.stackexchange.com/questions/79064/how-to-export-variables-from-a-file](https://unix.stackexchange.com/questions/79064/how-to-export-variables-from-a-file)

---

_[View the full topic](https://www.debian-fr.org/t/bash-variables-comment-les-utiliser-en-dehors-du-fichier/74746)._
