![]() | Red Hat Certified System Administration 8 |
Chapter 19: An Introduction to Bash Shell ScriptingSommaireBash ScriptingConditional StructuresIterative StructuresScripting StepsExercice : Table de MultiplicationEcrire un script qui demande a l'utilisateur de saisir la valeur de la table puis affiche la table de multiplication correspondanteResolution[root@redhat ~]# mkdir SCRIPTS[root@redhat ~]# touch SCRIPTS/table [root@redhat ~]# chmod SCRIPTS/table [root@redhat ~]# vi SCRIPTS/table Edit and run file [root@redhat ~]# SCRIPTS/table Script # !/bin/bash echo "Saisir la table que vous voulez:" read a echo "TABLE DE MULTIPLICTION PAR $a" for b in 0 1 2 3 4 5 6 7 8 9 10 11 12 do c=`expr $a \* $b` echo "$a x $b = $c" done Exercice : Testeur de fichiers executablesEcrire un script qui prend en argument le nom d'un fichier puis affiche si le fichier est executable ou pasResolution[root@redhat ~]# touch SCRIPTS/test[root@redhat ~]# chmod 777 SCRIPTS/testor Script #!/bin/bash if [ -x $1 ] then echo "YES $1 est un executable" else echo "$1 n'est pas executable" fi |