<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 { font-size: small; }
</style>
<title>Paramètres - 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="paramShell.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="shellScript.fre.html" title="Scripts">
<link rel="next" href="testShell.fre.html" title="Tests">
<link rel="last" href="tpShell.fre.html" title="Travaux Pratiques">
</head>
<body>
<h1>Paramètres - 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">Variables d'environnement</a></li>
<li><a href="shellScript.fre.html">Scripts</a></li>
<li><a href="paramShell.fre.html" id="subcurrent">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><a name="param"></a>
Récupération des paramètres de la ligne de commande
</h2>
<table border="1" class="var">
<tbody>
<tr>
<th>$0</th>
<td>nom de la commande</td>
</tr>
<tr>
<th>$n</th>
<td>valeur du n<sup>ième</sup> paramètre</td>
</tr>
<tr>
<th>$#</th>
<td>nombre de paramètres</td>
</tr>
<tr>
<th>$*</th>
<td>liste de tous les paramètres</td>
</tr>
</tbody>
</table>
<p>
Pour la ligne de commande <code>sh test.sh a b c</code>,
<code>$0</code> vaut <code>test.sh</code>, <code>$#</code> vaut
<code>3</code>, <code>$*</code> vaut <code>a b c</code>, et
<code>$2</code> vaut <code>b</code> (à l'intérieur du script).
</p>
<p>
La commande <code>shift</code> décale les
paramètres (en perdant le premier) : le
deuxième paramètre devient le premier, le
troisième devient le deuxième, etc. (c'est utile
quand on utilise une boucle pour traiter les paramètres).
</p>
<h2><a name="speciales"></a>
Variables spéciales
</h2>
<table border="1" class="var">
<tbody>
<tr>
<th>$$</th>
<td>numéro de processus de la dernière commande</td>
</tr>
<tr>
<th>$?</th>
<td>statut de la dernière commande (0 = tout s'est bien passé)</td>
</tr>
</tbody>
</table>
<h2><a name="speciaux"></a>
Caractères spéciaux
</h2>
<p>
Comme à chaque fois qu'on a un caractère
spécial (par exemple <code>$</code>), on a des
caractères d'échappement.
</p>
<table border="1" class="var">
<tbody>
<tr>
<th>\</th>
<td>banalise le caractère suivant</td>
<th>echo \$0 $0</th>
<td>$0 /usr/bin/ksh</td>
</tr>
<tr>
<th>" ... "</th>
<td>banalise les caractères sauf <code>\</code>, <code>$</code> et <code>`</code></td>
<th>echo "\$0 $0"</th>
<td>$0 /usr/bin/ksh</td>
</tr>
<tr>
<th>' ... '</th>
<td>banalise tous les caractères</td>
<th>echo '\$0 $0'</th>
<td>\$0 $0</td>
</tr>
<tr>
<th>` ... `</th>
<td>substitution de commande</td>
<th>echo `date`</th>
<td>Mon May 5 16:54:14 MEST 2003</td>
</tr>
</tbody>
</table>
</div>
<hr>
<address><a href="mailto:philippe.houdry@inist.fr">Philippe.Houdry@inist.fr</a></address>
</body>
</html>