<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="fr">
		<id>http://www.minetti.org/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Shell_script%3AInstructions_conditionnelles_et_boucles</id>
		<title>Shell script:Instructions conditionnelles et boucles - Historique des versions</title>
		<link rel="self" type="application/atom+xml" href="http://www.minetti.org/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Shell_script%3AInstructions_conditionnelles_et_boucles"/>
		<link rel="alternate" type="text/html" href="http://www.minetti.org/mediawiki/index.php?title=Shell_script:Instructions_conditionnelles_et_boucles&amp;action=history"/>
		<updated>2026-05-04T14:26:39Z</updated>
		<subtitle>Historique pour cette page sur le wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://www.minetti.org/mediawiki/index.php?title=Shell_script:Instructions_conditionnelles_et_boucles&amp;diff=161&amp;oldid=prev</id>
		<title>Jp : Page créée avec « == L'instruction conditionnelle IF == L'instruction conditionnelle IF a la forme suivante:  if [ ''test A'' ]; then      ''...... »</title>
		<link rel="alternate" type="text/html" href="http://www.minetti.org/mediawiki/index.php?title=Shell_script:Instructions_conditionnelles_et_boucles&amp;diff=161&amp;oldid=prev"/>
				<updated>2016-04-07T19:20:23Z</updated>
		
		<summary type="html">&lt;p&gt;Page créée avec « == L&amp;#039;instruction conditionnelle IF == L&amp;#039;instruction conditionnelle IF a la forme suivante:  if [ &amp;#039;&amp;#039;&lt;a href=&quot;/wiki/Shell_script:Expressions_conditionnelles&quot; title=&quot;Shell script:Expressions conditionnelles&quot;&gt;test A&lt;/a&gt;&amp;#039;&amp;#039; ]; then      &amp;#039;&amp;#039;...... »&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nouvelle page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== L'instruction conditionnelle IF ==&lt;br /&gt;
L'instruction conditionnelle IF a la forme suivante:&lt;br /&gt;
 if [ ''[[Shell_script:Expressions_conditionnelles|test A]]'' ]; then&lt;br /&gt;
     ''...''&lt;br /&gt;
     ''Instruction''&lt;br /&gt;
     ''...''&lt;br /&gt;
 elif [ ''[[Shell_script:Expressions_conditionnelles|test B]]'' ]; then&lt;br /&gt;
     ''...''&lt;br /&gt;
     ''Instruction''&lt;br /&gt;
     ''...''&lt;br /&gt;
 else&lt;br /&gt;
     ''...''&lt;br /&gt;
     ''Instruction''&lt;br /&gt;
     ''...''&lt;br /&gt;
 fi&lt;br /&gt;
Il faut faire attention de laisser des espaces entre les crochets encadrant l'expression conditionnelle.&lt;br /&gt;
&lt;br /&gt;
== Boucle pour lister le contenu d'un répertoire ==&lt;br /&gt;
Pour traiter le contenu d'un répertoire:&lt;br /&gt;
 for FILE in &amp;quot;$PATH_TO_TREAT/*&amp;quot; ; do&lt;br /&gt;
     if [ &amp;quot;$FILE&amp;quot; != &amp;quot;$PATH_TO_TREAT/*&amp;quot; ]; then&lt;br /&gt;
         ''...''&lt;br /&gt;
         ''Instruction''&lt;br /&gt;
         ''...''&lt;br /&gt;
     fi&lt;br /&gt;
 done&lt;br /&gt;
Pour la prise en compte des fichiers cachés:&lt;br /&gt;
 for FILE in &amp;quot;$PATH_TO_TREAT/.*&amp;quot; ; do&lt;br /&gt;
     if [ &amp;quot;$FILE&amp;quot; != &amp;quot;$PATH_TO_TREAT/.&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;$FILE&amp;quot; != &amp;quot;$PATH_TO_TREAT/..&amp;quot; ]; then&lt;br /&gt;
         ''...''&lt;br /&gt;
         ''Instruction''&lt;br /&gt;
         ''...''&lt;br /&gt;
     fi&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
== Boucle pour parser un fichier ==&lt;br /&gt;
=== Tableau ===&lt;br /&gt;
Pour extraire les données d'un fichier sous forme de tableau:&lt;br /&gt;
 while IFS=: read user pass uid gid full home shell; do&lt;br /&gt;
     echo -e &amp;quot;$full :\n\&lt;br /&gt;
        Pseudo : $user\n\&lt;br /&gt;
        UID :\t $uid\n\&lt;br /&gt;
        GID :\t $gid\n\&lt;br /&gt;
        Home :\t $home\n\&lt;br /&gt;
        Shell :\t $shell\n\n&amp;quot;&lt;br /&gt;
 done &amp;lt; /etc/passwd&lt;br /&gt;
IFS indique le caractère de séparation. Par défaut c'est le caractère espace qui est pris.&lt;br /&gt;
&lt;br /&gt;
Autre exemple avec un caractère '''tabulation''' comme séparateur:&lt;br /&gt;
 TAB=$( printf &amp;quot;\t&amp;quot; )&lt;br /&gt;
 while IFS=$TAB read user pass uid gid full home shell; do&lt;br /&gt;
     echo -e &amp;quot;$full :\n\&lt;br /&gt;
        Pseudo : $user\n\&lt;br /&gt;
        UID :\t $uid\n\&lt;br /&gt;
        GID :\t $gid\n\&lt;br /&gt;
        Home :\t $home\n\&lt;br /&gt;
        Shell :\t $shell\n\n&amp;quot;&lt;br /&gt;
 done &amp;lt; /var/minetti/passwd&lt;br /&gt;
&lt;br /&gt;
== Liens externes ==&lt;br /&gt;
[http://www.commentcamarche.net/faq/5027-comment-lire-un-fichier-ligne-par-ligne commentcamarche.net: Comment lire un fichier ligne par ligne]&lt;/div&gt;</summary>
		<author><name>Jp</name></author>	</entry>

	</feed>