OpenGnsys  1.1.1
String.lib
Ir a la documentación de este archivo.
1 #!/bin/bash
2 
3 # ##
17 
19 {
20 local i
21 # Si se solicita, mostrar ayuda.
22 if [ "$*" == "help" ]; then
23  ogHelp "$FUNCNAME str_elemento str_grupo" \
24  "$FUNCNAME full-duplex \"full-duplex half-duplex broadcast\" "
25  return
26 fi
27 
28 # Error si no se recibe 2 parámetro.
29 [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
30 
31 
32 for i in `echo $2`
33 do
34  if [ "$1" == "$i" ]
35  then
36  return 0
37  fi
38 done
39 
40 return 1
41 }
42 
43 # ##
57 
59 {
60 
61 local REG
62 
63 # Si se solicita, mostrar ayuda.
64 if [ "$*" == "help" ]; then
65  ogHelp "$FUNCNAME str_elemento str_expresión_regular" \
66  "$FUNCNAME 50M \"^[0-9]{1,2}\M$\" "
67  return
68 fi
69 
70 # Error si no se recibe 2 parámetro.
71 [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
72 
73 REG=$2
74 [[ $1 =~ $REG ]] && return 0 || return 1
75 }
76 
77 
78 
79 # ##
92 
93 function ogCheckIpAddress()
94 {
95 local REG IP arrIP
96 
97 # Si se solicita, mostrar ayuda.
98 if [ "$*" == "help" ]; then
99  ogHelp "$FUNCNAME str_IpAddressToCheck" \
100  "$FUNCNAME 192.18.35.3"
101  return
102 fi
103 
104 # Error si no se recibe 1 parámetro.
105 [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
106 
107 
108 IP=$1
109 REG="^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"
110 if [[ "$IP" =~ $REG ]]
111 then
112  OIFS=$IFS;
113  IFS='.' ;
114  arrIP=($IP)
115  IFS=$OIFS
116  if [[ ${arrIP[0]} -le 255 && ${arrIP[1]} -le 255 && ${arrIP[2]} -le 255 && ${arrIP[3]} -le 255 ]]
117  then
118  return 0
119  fi
120 fi
121 return 1
122 }
function ogRaiseError()
Devuelve el mensaje y el código de error correspondiente. #.
Definition: System.lib:188
function ogHelp()
Muestra mensaje de ayuda para una función determinda. #.
Definition: System.lib:153
function ogCheckStringInReg()
Función para determinar si el elemento contiene una "expresión regular" #.
Definition: String.lib:58
function ogCheckStringInGroup()
Función para determinar si el elemento pertenece a un conjunto #.
Definition: String.lib:18
function ogCheckIpAddress()
Función para determinar si una cadena es una dirección ipv4 válida #.
Definition: String.lib:93