<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <link REL="STYLESHEET" TYPE="text/css" TITLE="Style DILIB" HREF="../../dilib.css"> <style type="text/css"> .remarque, .remarque_suite { font-size: smaller; } .remarque:before { content: "Remarque :" } .attention { font-style: italic; } .attention:before { content: "ATTENTION :"; } .remarque { margin-bottom: 2; } .remarque_suite { margin-bottom: 2; margin-top: 0; } </style> <title>Variables d'environnement - Shell - UNIX</title> <link rel="copyright" href="http://www.inist.fr/"><link rel="author" href="http://dilib.inist.fr/membres.html"><link rel="chapter" href="caracteristiques.fre.html" title="UNIX"><link rel="chapter" href="X.fre.html" title="X Window"><link rel="chapter" href="redirPipes.fre.html" title="Rappels"><link rel="chapter" href="newCommandsUser.fre.html" title="Commandes UNIX"><link rel="chapter" href="shellVars.fre.html" title="Shell"><link rel="chapter" href="sed.fre.html" title="Sed"><link rel="chapter" href="make.fre.html" title="Make"><link rel="index" href="http://dilib.inist.fr/dilib/v04Main/IndexSite/Server/FR.resource.index.html"><link rel="top" title="Accueil de DILIB" href="http://dilib.inist.fr/dilib/v04Main/"><link rel="alternate" title="English version" href="shellVars.eng.html"><link rel="up" href="index.fre.html" title="Tutorial UNIX / Shell"> <link rel="section" href="shellVars.fre.html" title="Variables d'environnement"><link rel="section" href="shellScript.fre.html" title="Scripts"><link rel="section" href="paramShell.fre.html" title="Paramètres"><link rel="section" href="testShell.fre.html" title="Tests"><link rel="section" href="structureShell.fre.html" title="Structures de contrôle"><link rel="section" href="commandeShell.fre.html" title="Commandes diverses"><link rel="section" href="tpShell.fre.html" title="Travaux Pratiques"> <link rel="first" href="caracteristiques.fre.html" title="Caractéristiques d'UNIX"> <link rel="previous" href="tpNewCommands.fre.html" title="Travaux Pratiques"> <link rel="next" href="shellScript.fre.html" title="Scripts"> <link rel="last" href="tpShell.fre.html" title="Travaux Pratiques"> </head> <body> <h1>Variables d'environnement - Shell - UNIX</h1> <div id="navcontainer"> <ul id="navlist"> <li><a href="caracteristiques.fre.html">UNIX</a> </li> <li><a href="redirPipes.fre.html">Bases</a> </li> <li><a href="newCommandsUser.fre.html">Commandes</a> </li> <li><a>Shell</a> <ul id="subnavlist"> <li><a href="shellVars.fre.html" id="subcurrent">Variables d'environnement</a></li> <li><a href="shellScript.fre.html">Scripts</a></li> <li><a href="paramShell.fre.html">Paramètres</a></li> <li><a href="testShell.fre.html">Tests</a></li> <li><a href="structureShell.fre.html">Structures de contrôle</a></li> <li><a href="commandeShell.fre.html">Commandes</a></li> <li><a href="tpShell.fre.html">TP</a></li> </ul> </li> <li><a href="sed.fre.html">Sed</a> </li> <li><a href="make.fre.html">Make</a> </li> </ul> </div> <div class="content"> <h2>Variables d'environnement</h2> <p> Le shell contient diverses variables d'environnement. Si vous voulez les voir toutes, utilisez la commande <code>set</code> sans paramètre. </p> <p> Certaines de ces variables peuvent nous intéresser plus particulièrement (pour visualiser leur contenu, utilisez la commande <code>echo</code>, par exemple <code>echo $HOME</code> pour afficher le contenu de la variable <code>HOME</code>) : </p> <table class="var" border="1"> <tbody> <tr> <th>nom</th> <th>contenu</th> </tr> <tr> <td>HOME</td> <td>chemin de votre "home directory"</td> </tr> <tr> <td>PATH</td> <td> liste des chemins parcourus par le shell pour trouver les commandes à exécuter (quand le chemin complet n'est pas précisé) </td> </tr> <tr> <td>PS1</td> <td>"Prompt" utilisé dans le shell (on peut modifier sa valeur)</td> </tr> <tr> <td>SHELL</td> <td>indique le shell qu'on utilise</td> </tr> </tbody> </table> <p> Pour modifier la valeur d'une variable (ou en créer une), il suffit d'utiliser la syntaxe : </p> <pre>VARIABLE=valeur</pre> <p class="attention"> Il ne faut pas mettre d'espace autour du caractère <code>=</code> </p> <p> Par convention, les noms de variable sont en majuscules. Pour accéder à la valeur d'une variable, on utilise : </p> <pre>$VARIABLE</pre> <p> ou, pour éviter des ambiguités (si a="var", <code>${a}b</code> renvoie <code>varb</code> alors que <code>$ab</code> est invalide) : </p> <pre>${VARIABLE}</pre> <p> Une variable n'est disponible que dans le shell où on l'a initialisée. </p> <p> On peut créer des variables utilisateurs de la même manière. </p> </div> <hr> <address><a href="mailto:philippe.houdry@inist.fr">Philippe.Houdry@inist.fr</a></address> </body> </html>