Good night,
Today we are going to have something basic but quite useful. Let's see some examples of options menus in shell script.

Bash
#!/bin/bash
#rokitohBash
usage()
{
cat << EOF
USO: $0 -n <OPCION UNO> -p <OPCION DOS> -h <OPCION TRES>text
Ejemplo menú de opcionestext
OPCIONES:
-n OPCION UNO
-m OPCION DOS
-p OPCION TRESBash
EOF
}
#Declaramos todas las variables que se van a usar para guardar los parametros
uno=
dos=
tres=
#Usamos el getopts para guardar los parametros en variables
while getopts “n:m:p:” OPTIONBash
do
case $OPTION intext
n)
uno=$OPTARG
;;
m)
dos=$OPTARG
;;text
p)
tres=$OPTARG
;;Bash
esac
donetext
#Comprobamos que se han introducido los parametros obligatoriosBash
if [ -z $uno] || [ -z $dos ] || [ -z $tres ];
then
usage
exit 1Bash
fiAnother example:
|
Bash text text Bash text php php php php php Bash text Bash text text text text php php text text Bash |
Greetings, rokitoh!
Comments