Newer
Older
cours-unix-shell / UnixShell_cours2018 / shellVars.fre.html
<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&egrave;tres"><link rel="section" href="testShell.fre.html" title="Tests"><link rel="section" href="structureShell.fre.html" title="Structures de contr&ocirc;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&eacute;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&egrave;tres</a></li>
	    <li><a href="testShell.fre.html">Tests</a></li>
	    <li><a href="structureShell.fre.html">Structures de contr&ocirc;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&egrave;tre.
    </p>
    <p>
      Certaines de ces variables peuvent nous int&eacute;resser plus
      particuli&egrave;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>)&nbsp;:
    </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 &agrave; ex&eacute;cuter (quand le chemin
	    complet n'est pas pr&eacute;cis&eacute;)
	  </td>
	</tr>
	<tr>
	  
	  <td>PS1</td>
	  <td>"Prompt" utilis&eacute; 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&eacute;er une), il
      suffit d'utiliser la syntaxe&nbsp;:
    </p>
    <pre>VARIABLE=valeur</pre>
    <p class="attention">
      Il ne faut pas mettre d'espace autour du caract&egrave;re <code>=</code>
    </p>
    <p>
      Par convention, les noms de variable sont en majuscules. Pour
      acc&eacute;der &agrave; la valeur d'une variable, on utilise&nbsp;:
    </p>
    <pre>$VARIABLE</pre>
    <p>
      ou, pour &eacute;viter des ambiguit&eacute;s (si a="var",
      <code>${a}b</code> renvoie <code>varb</code> alors que
      <code>$ab</code> est invalide)&nbsp;:
    </p>
    <pre>${VARIABLE}</pre>
    <p>
      Une variable n'est disponible que dans le shell o&ugrave; on l'a
      initialis&eacute;e.
    </p>
    <p>
      On peut cr&eacute;er des variables utilisateurs de la m&ecirc;me 
      mani&egrave;re.
    </p>
    </div>
    <hr>
    <address><a href="mailto:philippe.houdry@inist.fr">Philippe.Houdry@inist.fr</a></address>
  </body>
</html>