|
Erreur numéro 1
Script (erreur_1.sh)
#! /bin/sh
i=0 while [ $i -le 5 ]; do echo $i i = $(($i + 1)) done
Résultat d'exécution
$ ./erreur_1.sh ./erreur_1.sh: line 6: i: command not found 0 ./erreur_1.sh: line 6: i: command not found 0 ./erreur_1.sh: line 6: i: command not found 0 [...] (Ctrl-C) $
Explication
Solution
Erreur numéro 2
Script (erreur_2.sh)
#! /bin/sh
for i in 1 2 3 4 ; do $j=$(($i * $i)) echo "$i² = $j" done
Résultat d'exécution
$ ./erreur_2.sh ./erreur_2.sh: line 4: =1: command not found 1² = ./erreur_2.sh: line 4: =4: command not found 2² = ./erreur_2.sh: line 4: =9: command not found 3² = ./erreur_2.sh: line 4: =16: command not found 4² = $
Explication
Solution
Erreur numéro 3
Script (erreur 3.sh)
#! /bin/sh
printf "Voulez-vous quitter (O/N) " read reponse if [ "$reponse" = "O"] then exit fi printf "suite du script...."
Résultat d'exécution
$ ./erreur_3.sh Voulez-vous quitter (O/N) N ./erreur_3.sh: line 5: [: missing `]' suite du script.... $
Explication
Solution
Erreur numéro 4
Script (erreur_4.sh)
#! /bin/sh
printf "Indiquez un nom de fichier : " read fichier if [ ! -e $fichier ]; then printf "Il n'existe pas\n" exit fi if [ -d $fichier ]; then printf "C'est un répertoire\n" exit fi if [ ! -f $fichier ]; then printf "Ce n'est pas un fichier normal\n" exit fi
printf "Ok !\n"
Résultat d'exécution
$ ./erreur_4.sh Indiquez un nom de fichier : /etc C'est un répertoire $ ./erreur_4.sh Indiquez un nom de fichier : /etc/passwd Ok !
$ ./erreur_4.sh Indiquez un nom de fichier : Mes Documents ./erreur_4.sh: line 5: [: Mes: binary operator expected ./erreur_4.sh: line 9: [: Mes: binary operator expected ./erreur_4.sh: line 13: [: Mes: binary operator expected Ok ! $
Explication
Solution
Erreur numéro 5
Script (erreur_5.sh)
function confirmation() { while true; do printf "(Y/N) ?" read rep if [ "$rep" = "Y" ]; then return 0; fi if [ "$rep" = "N" ]; then return 1; fi done }
# parcours des repertoires for rep in Documents Donnees Scripts do printf "Sauvegarder $rep ?" if confirmation; then sauvegarder_repertoire $rep fi done
Explication
Solution
Erreur numéro 6
Script (erreur_6.sh)
#! /bin/sh
minimum="$1" for i in "$@" do if [ "$i" -lt "$minimum" ] then miminum="$i" fi done
echo "La plus petite valeur est $miminum"
Résultat d'exécution
$ ./erreur_6.sh 16 23 4 8 24 15 La plus petite valeur est $
Explication
Solution
Erreur numero 7
Script (erreur_7.sh)
#! /bin/sh
jour[0]="Lundi" jour[1]="Mardi" jour[2]="Mercredi" jour[3]="Jeudi" jour[4]="Vendredi" jour[5]="Samedi" jour[6]="Dimanche"
for i in 0 1 2 3 4 5 6 do echo "Jour $i -> $jour[$i]" done
Résultat d'exécution
$ ./erreur_7.sh Jour 0 -> Lundi[0] Jour 1 -> Lundi[1] Jour 2 -> Lundi[2] Jour 3 -> Lundi[3] Jour 4 -> Lundi[4] Jour 5 -> Lundi[5] Jour 6 -> Lundi[6] $
Explication
Solution
Erreur numéro 8
Script (erreur_8.sh)
#! /bin/sh
echo "Inserez le CD d'installation" read mount /mnt/cdrom || { echo "Impossible de monter le CD"; exit 1 } tar -xf /mnt/cdrom/install.tar || { echo "Erreur d'install"; exit 1 }
Résultat d'exécution
$ ./erreur_8.sh Inserez le CD d'installation (Entrée) ./erreur_8.sh: line 7: syntax error: unexpected end of file $
Explication
Solution
Erreur numéro 9
Script (erreur_9.sh)
#! /bin/sh
find /etc -type f 2>/dev/null | wc -l | read nb
echo "il y a $nb fichiers normaux dans l'arborescence /etc"
Résultat d'exécution
$ ./erreur_9.sh il y a fichiers normaux dans l'arborescence /etc $
Explication
$ ./erreur_9.sh il y a 1619 fichiers normaux dans l'arborescence /etc $
Solution
nb=$( find /etc -type f 2>/dev/null | wc -l)
Erreur numéro 10
Résultat d'exécution
$ a=test $ echo $a test $
$ a=test 2 bash: 2: command not found $
$ a=`test 2` $ echo $a
$
Explication
Solution
|