-
Notifications
You must be signed in to change notification settings - Fork 17
/
Generar_Diccionario_Numerico.sh
executable file
·116 lines (104 loc) · 2.36 KB
/
Generar_Diccionario_Numerico.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
#Script realizado por Raúl Caro Pastoriono (fryntiz) fryntiz@gmail.com
#GitHub --> https://github.com/fryntiz
#Variables Generales
eliminar_ceros=false
escribir_salida=false
##### CONSTANTES COLORES #####
rojo="\033[0;31m"
verde="\033[0;32m"
azul="\033[0;34m"
magenta="\033[0;35m"
cyan="\033[01;36m"
grisC="\033[0;37m"
gris="\033[1;30m"
rojoC="\033[1;31m"
verdeC="\033[1;32m"
amarillo="\033[1;33m"
azulC="\033[1;34m"
magentaC="\033[1;35m"
cyanC="\033[1;36m"
blanco="\033[1;37m"
clear
mensaje() {
echo -e " $rojoC Modo de uso:"
echo -e " $amarillo$0 [OPCIONES]"
echo -e " $blanco Ejemplo:$rojoC$0 -z -o Diccionario_Años"
echo ""
echo -e " $azulC Opciones:"
echo -e " $cyanC -h, Mostrar esta ayuda"
echo -e " $verdeC -z, Omitir ceros en los diccionarios"
echo -e " $cyanC -o, Especificar archivo de salida."
echo ""
echo ""
echo -e "$amarillo Este script generará todos los números comprendidos entre los dos valores que introduzcas$blanco"
echo ""
}
if [ $# -eq 0 ] #Comprueba que existen parámentros
then
mensaje
exit 1
fi
while getopts "zho:" Opcion
do
case $Opcion in
h)
echo "Menu de ayuda"
echo ""
mensaje
exit 1
;;
z)
eliminar_ceros=true
;;
o)
salida=$OPTARG
escribir_salida=true
;;
?)
echo "opción $OPTARG no reconocida"
;;
:)
echo "opción $OPTARG requiere un argumento"
;;
esac
done
shift $(( OPTIND -1 ))
echo ""
echo ""
echo -e "$verdeC Introduce solo un valor numérico entero"
echo -e "$rojoC"
read -p " Introduce el numero de inicio: " numero_actual
read -p " Introduce el numero de fin: " numero_final
echo -e "$blanco"
while [ $numero_actual -lt $numero_final ]
do
echo -e "$azulC Calculando número actual: $verdeC$numero_actual"
if [ $eliminar_ceros == true ]
then
if [ $escribir_salida == true ]
then
echo $numero_actual | tr -d "0" >> /tmp/$salida
else
echo $numero_actual | tr -d "0"
fi
else
if [ $escribir_salida == true ]
then
echo $numero_actual >> /tmp/$salida
else
echo $numero_actual
fi
fi
let numero_actual++
done
echo -e "$blanco"
if [ $escribir_salida == true ]
then
cat /tmp/$salida > $salida
sleep 2
rm /tmp/$salida
else
echo "Solo mostrando datos sin guardar en archivos (parámetro '-o')"
fi
#Script realizado por Raúl Caro Pastoriono (fryntiz)