"depot M111"

This commit is contained in:
JunkJumper
2020-05-03 14:10:04 +02:00
parent 0e8d905c4e
commit 78cdd39ea9
54 changed files with 610 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,21 @@
#!/bin/bash
# M111 - TP9 - afficheargs.sh
echo $*
for i in $*
do
echo $i
done
for i
do
echo $i
done
while test $# != 0 # ou bien [ ou bien [[
do
echo $1
shift
done

View File

@ -0,0 +1,33 @@
#! /bin/bash
# M111 - TP11 - ajouterposte.sh (version prototype a terminer)
# Ajout a la fin d'un fichier (ou creation du fichier) de lignes composées
# d'un mot, chaque mot terminé par 00 à 99.
# Le fichier de nom FICHIER-DES-SALLES se trouve dans le répertoire indiqué
# par la variable d'environnement REP_SALLES.
# Exemple :
# $ q6 S756P 01 11
# $ cat $REP_SALLES/FICHIER-DES-SALLES
# S756P01
# S756P02
# S756P03
# S756P05
# S756P06
# S756P07
# S756P08
# S756P09
# S756P10
# S756P11
# $
if [[ $# -ne 3 ]] ; then echo "Syntaxe : $0 salle debut fin" ; exit 2 ; fi
if [[ ! -d $REP_SALLES ]] ; then echo '$REP_SALLE absente ou incorrecte' ; exit 2 ; fi
if [[ $3 -gt 99 ]] ; then echo "Nombre entre 0 et 99 !" ; exit 2 ; fi
for NB in $(seq $2 $3)
do
if [[ $NB -le 9 ]]
then echo ${1}0$NB
else echo $1$NB
fi
done >> $REP_SALLES/FICHIER-DES-SALLES

View File

@ -0,0 +1,16 @@
#!/bin/bash
# Version avec 'stat'
somme=0
for i in *
do
if [ -f $i ]
then
taille=$(stat -c%s $i)
let somme=somme+taille
echo "... Mise au point " $i $taille $somme >&2
fi
done
echo $somme

View File

@ -0,0 +1,13 @@
#!/bin/bash
# Version avec 'ls' et 'read'
ls -l | grep '^-' | { somme=0 ; while read m1 m2 m3 m4 taille m6
do
let somme=somme+taille
echo "... Mise au point " $i $taille $somme >&2
done
echo $somme
}

View File

@ -0,0 +1,14 @@
#!/bin/bash
# Version avec 'ls' et 'set'
ls -l | grep '^-' | { somme=0; while read neutre ligne
do
set $ligne
let somme=somme+$4
echo "... Mise au point " $i $taille $somme >&2
done
echo $somme
}

View File

@ -0,0 +1,10 @@
#! /bin/bash
# M111 - TP9 - concatene.sh
rm -rf GROSFICHIER
for FICH in TEST/*
do
cat $FICH >> GROSFICHIER
done

19
SCRIPTS_EXEMPLES/egaltilde.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash - egaltilde.sh
# M111 - TP11 - reconnaitre un mot commencant
# par un caractere particulier
if [[ $# -le 1 ]]
then echo "Syntaxe : $0 caractere mot ..."
exit 5
fi
LECAR=$1
shift
while [[ ! $1 =~ $LECAR && -n $1 ]]
do
LESMOTS="$LESMOTS $1"
echo ' boucle ...'
shift
done
echo ' 'LESMOTS=\'$LESMOTS\'

View File

@ -0,0 +1,7 @@
MOT='<esscai.c>'
echo Valeur de LIGNE = $MOT
echo ${MOT//.c/.o}
basename /usr/bin/fichier.c
basename --suffix=.c fichier.c
basename /home/TP
dirname /usr/bin/gcc

17
SCRIPTS_EXEMPLES/somme_args.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
# M111 - TP9 - sommeargs.sh (prototype)
# solution avec seq possible ...
if [[ $# -ne 2 ]]
then echo "Syntaxe : $0 nbre1 nombre2 # avec nbre1 <= nbre2" ; exit 2 ; fi
NB1=$1
NB2=$2
SOMME=0
while [[ $NB1 -le $NB2 ]]
do
let SOMME=SOMME+NB1
let NB1++
done
echo $SOMME

BIN
SCRIPTS_EXEMPLES/strings.JPG Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

View File

@ -0,0 +1,47 @@
#! /bin/bash
# traite_arguments.sh : exemple de script pour traiter les arguments de la ligne de commande
# - avec passage d'arguments (simples ou couple) dans un ordre quelconque
# - avec initialisation des variables associées aux parametres pour traitement ulterieur
# - Affichage des valeurs des variables concernees
# Arguments possibles :
# -x1 -x2 --var_x2
# -a1 valeur -argument1 valeur -a2 valeur --argument2
# Exemple :
# traite_arguments.sh -a1 val1 --argument1 val11 -x1 -a2 val2 -x2 # nb : redondance
varX1=0 ; varX2=0
variable1=NON ; variable2=NON
echo Nombre d arguments = $#
while [[ $# -gt 0 ]] ; do
case $1 in
"-x1" ) varX1=1
shift ;;
"-x2" | "--var_x2" ) varX2=1
shift
;;
"-d" | "--argument1" )
if [[ -n $2 ]]
then
if [ -d $2 ]
variable1=$2
else
echo "$0: Syntaxe : $1 <valeur>" ; exit 2
fi
shift ; shift ;;
"-a2" | "--argument2" )
if [[ -n $2 ]]
then variable2=$2
else
echo "$0: Syntaxe : $1 <valeur>" ; exit 2
fi
shift ; shift ;;
* ) echo "$0: Syntaxe : $1 = parametre illegal" ; exit 2
esac
done