Skip to content

Instantly share code, notes, and snippets.

@ninotae
Created July 30, 2017 13:57
Show Gist options
  • Select an option

  • Save ninotae/0b1c0585caf5030d362750c23bbcd9a0 to your computer and use it in GitHub Desktop.

Select an option

Save ninotae/0b1c0585caf5030d362750c23bbcd9a0 to your computer and use it in GitHub Desktop.
Create menu
#!/bin/bash
#### 1. Déclaration de variables
GRN="\033[0;32m"
RED="\033[0;31m"
RESET="\033[0m"
#### 2. Début du script
while [[ -n $1 ]] ; do # tant que $1 sera non null (donc que $1 n'aura pas de valeur renseignée)
case $1 in
-h|--help)
echo "usage : createuser.sh -b <base name> -n <number> -s <start number>"
exit 1
;;
-b|--base)
if [[ "$2" != -* && "$2" != "" ]] ; then # Si $2 commence par - et est non-null alors il popule la variable "base"
base=$2
shift 1
else
echo "syntax error"
exit 2
fi
;;
-n|--number)
if [[ "$2" != -* && "$2" != "" ]] ; then
nbac=$2
shift 1
else
echo "syntax error"
exit 2
fi
;;
-s|--start-number)
if [[ "$2" != -* && "$2" != "" ]] ; then
nbcom=$2
shift 1
else
echo "syntax error"
exit 2
fi
;;
-D|--debug)
declare -i debug=666
shift 1
;;
*)
echo "syntax error"
exit 2
;;
esac
shift 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment