Compare commits

..

1 Commits

Author SHA1 Message Date
0ba83cd768 solution 2021-06-22 10:11:20 +02:00
4 changed files with 15 additions and 24 deletions

View File

@@ -1,17 +1,5 @@
## Fonctions ## Fonctions
### Exercice 1
Voir le fichier eval.sh
Essayez d'identifier sa fonction
Identifiez ses lacunes
Proposez une correction
### Exercice 2
Définir dans le fichier myfunctions.sh une fonction "myerror" prenant 2 arguments en entrée: un code et un message. Définir dans le fichier myfunctions.sh une fonction "myerror" prenant 2 arguments en entrée: un code et un message.

12
eval.sh
View File

@@ -1,12 +0,0 @@
#! /bin/bash
IFS=$'\n\t'
host=$1
root=${host}/rootfs
host=$(basename $host)
hostname=$(grep HOSTNAME ${root}/etc/sysconfig/network 2>/dev/null| cut -f2 -d=)
stat --printf "%y;" ${root}/root/.bash_history
stat --printf "%y;" ${root}/home/formation/.bash_history
stat --printf "%y;" ${root}/etc/motd
if( grep -i -qE "today" ${root}/etc/profile.d/zalias.sh ) ; then echo -ne "1;" ; else echo -ne "0;" fi
if( grep -i -qE "PS1" ${root}/etc/profile.d/zconf.sh ) ; then echo -ne "1;" ; else echo -ne "0;" fi
if( grep -i -qE "HISTSIZE" ${root}/etc/profile.d/zconf.sh ) ; then echo -ne "1;" ; else echo -ne "0;" fi

7
myfunctions.sh Normal file
View File

@@ -0,0 +1,7 @@
function myerror {
code=$1
shift
msg="$*"
echo $msg
exit $code
}

8
test.sh Normal file
View File

@@ -0,0 +1,8 @@
#! /bin/bash
set -e
set -u
source myfunctions.sh
myerror 42 hello world