diff options
| author | jerome <jerome@xlinfo.fr> | 2024-04-14 16:55:49 +0200 |
|---|---|---|
| committer | jerome <jerome@xlinfo.fr> | 2024-04-14 16:55:49 +0200 |
| commit | 91595d034f408e8482f21facec97f7c2fc7fba6a (patch) | |
| tree | e88b2a0c5e491f8e57eb9784c566bd1e6f0249a1 /exemple11 | |
| parent | 9c6790810256c826f71e0a0a3c4b54844cc24477 (diff) | |
| download | bash_tutorial-91595d034f408e8482f21facec97f7c2fc7fba6a.tar.gz bash_tutorial-91595d034f408e8482f21facec97f7c2fc7fba6a.zip | |
ajout de exemple11
Diffstat (limited to 'exemple11')
| -rwxr-xr-x | exemple11 | 48 |
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 !" + |
