mooc/www/sys/fs/usr/script/evalQ343b

73 lines
1.4 KiB
Plaintext
Raw Normal View History

2023-01-31 08:47:50 +04:00
#!/bin/bash
# Tahiry Razafindralambo
# v1.0 du 2019.05.30
2023-01-31 09:52:15 +04:00
# Pascal ANELLI
# v2.0 du 2020.03.30
# Session 3
2023-01-31 08:47:50 +04:00
source ${LIBSH}/libeval.sh
a=2
b=3
2023-01-31 09:52:15 +04:00
#--------------
challenge=C34Q3b
#--------------
# Debut
banniere $challenge
2023-01-31 08:47:50 +04:00
2023-01-31 09:52:15 +04:00
readline
2023-01-31 08:47:50 +04:00
2023-01-31 09:52:15 +04:00
# 1 doit contenir la commande expr
2023-01-31 08:47:50 +04:00
[ $(echo "$line" | grep -c 'expr') -eq 0 ]
step $(vraifaux $?) "Votre commande ne contient pas la commande expr" true
2023-01-31 09:52:15 +04:00
# 2 doit contenir un ((
2023-01-31 08:47:50 +04:00
[ $(echo "$line" | grep -c "((") -ne 0 ]
2023-01-31 09:52:15 +04:00
step $(vraifaux $?) "Il y a l'operateur abrege de let"
2023-01-31 08:47:50 +04:00
2023-01-31 09:52:15 +04:00
# 3 doit contenir un i
2023-01-31 08:47:50 +04:00
[ $(echo "$line" | grep -c "i") -ne 0 ]
2023-01-31 09:52:15 +04:00
step $(vraifaux $?) "Il y a la variable i"
2023-01-31 08:47:50 +04:00
2023-01-31 09:52:15 +04:00
# 4 doit contenir un a
2023-01-31 08:47:50 +04:00
[ $(echo "$line" | grep -c "a") -ne 0 ]
2023-01-31 09:52:15 +04:00
step $(vraifaux $?) "Il y a la variable a"
2023-01-31 08:47:50 +04:00
2023-01-31 09:52:15 +04:00
# 5 doit contenir un b
2023-01-31 08:47:50 +04:00
[ $(echo "$line" | grep -c "b") -ne 0 ]
2023-01-31 09:52:15 +04:00
step $(vraifaux $?) "Il y a la variable b"
2023-01-31 08:47:50 +04:00
err="$(mktemp)"
fres="$(mktemp)"
eval $line 1>$fres 2>$err
2023-01-31 09:52:15 +04:00
echo "$i" > "$fres"
2023-01-31 08:47:50 +04:00
2023-01-31 09:52:15 +04:00
# 6 le fichier d'erreur doit etre vide
2023-01-31 08:47:50 +04:00
[ ! -s "$err" ]
2023-01-31 09:52:15 +04:00
step $(vraifaux $?) "Votre calcul est sans erreur" true
2023-01-31 08:47:50 +04:00
2023-01-31 09:52:15 +04:00
# 7 un resultat existe
2023-01-31 08:47:50 +04:00
[ -s "$fres" ]
2023-01-31 09:52:15 +04:00
step $(vraifaux $?) "Un resultat a ete produit" true
2023-01-31 08:47:50 +04:00
2023-01-31 09:52:15 +04:00
# 8 accuracy
[ $(cat "$fres") == "6" ]
step $(vraifaux $?) "Le resultat est juste"
2023-01-31 08:47:50 +04:00
2023-01-31 09:52:15 +04:00
echo -e "\n Le resultat de votre calcul est: $(cat "$fres") \n"
2023-01-31 08:47:50 +04:00
2023-01-31 09:52:15 +04:00
#--------------------------------
# Fin
status "${challenge}_$res"
rm -f "$fres" "$err"
exit 0
2023-01-31 08:47:50 +04:00