summaryrefslogtreecommitdiff
path: root/exemple11
diff options
context:
space:
mode:
authorjerome <jerome@xlinfo.fr>2024-04-14 16:55:49 +0200
committerjerome <jerome@xlinfo.fr>2024-04-14 16:55:49 +0200
commit91595d034f408e8482f21facec97f7c2fc7fba6a (patch)
treee88b2a0c5e491f8e57eb9784c566bd1e6f0249a1 /exemple11
parent9c6790810256c826f71e0a0a3c4b54844cc24477 (diff)
downloadbash_tutorial-91595d034f408e8482f21facec97f7c2fc7fba6a.tar.gz
bash_tutorial-91595d034f408e8482f21facec97f7c2fc7fba6a.zip
ajout de exemple11
Diffstat (limited to 'exemple11')
-rwxr-xr-xexemple1148
1 files changed, 48 insertions, 0 deletions
diff --git a/exemple11 b/exemple11
new file mode 100755
index 0000000..cb8c7fd
--- /dev/null
+++ b/exemple11
@@ -0,0 +1,48 @@
+#!/usr/bin/bash
+# jeu du nombre mystérieux
+#set -x
+function aide(){
+ echo "Usage: $(basename $0) [-h] [-l limite]"
+ exit
+}
+
+if [ $# == 0 ];then
+ aide
+fi
+
+while getopts :hl: OPTION; do
+ case $OPTION in
+ h)
+ aide
+ ;;
+ l)
+ limite=$OPTARG
+ ;;
+ *)
+ aide
+ esac
+done
+
+echo " ---------------------- "
+echo "< Jeu du Nombre Mystère >"
+echo " ---------------------- "
+secret=$(( RANDOM % $limite +1 ))
+nb=0
+while [[ $secret != $reponse ]]
+do
+ ((nb++))
+ read -p "Entrez un nombre entre 0 et $limite : " reponse
+ if [[ $reponse = "q" || $reponse = "Q" ]];then
+ echo "Bye"
+ exit
+ fi
+ if [[ ! $reponse =~ ^[0-9]+$ || $reponse -gt $limite || $reponse -le 0 ]] ; then
+ echo "Hors de l'intervalle !"
+ elif [[ $reponse -gt $secret ]]; then
+ echo "Trop grand !"
+ elif [[ $reponse -lt $secret ]]; then
+ echo "Trop petit !"
+ fi
+done
+echo "Gagné en $nb coups !"
+