Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function ingresarDatos
- {
- opc1="y"
- while [ opc1 == "y" ]
- do
- read -p "Ingrese su nombre" nombre >> datos.txt
- read -p "Ingrese su apellido" apellido >> datos.txt
- read -p "Ingrese su edad" edad >> datos.txt
- read -p "Ingrese su cedula" ci >> datos.txt
- echo "\n"
- echo "¿Desea ingresar mas datos? [y/n]"
- read opc1
- done
- read -p "Para volver al menu principal ingrese x" volver
- if [[ $volver == "x" ]]; then
- menuPrincipal
- fi
- }
- function buscarDatos
- {
- read -p "Ingrese el nombre que quiere buscar" buscarNombre
- if grep -q $buscarNombre datos.txt
- then grep -i $buscarNombre datos.txt
- else echo "No existe el nombre"
- fi
- read -p "Para volver al menu principal ingrese x" volver
- if [ $volver == "x" ]
- then
- menuPrincipal
- fi
- }
- function eliminarDatos
- {
- read -p "Ingrese el dato que quiere borrar" borrarDato
- if grep -q $borrarDato datos.txt
- then grep -vi $borrarDato datos.txt
- grep -vi $borrarDato datos.txt > datos.txt
- else echo "No existe el dato"
- fi
- read -p "Para volver al menu principal ingrese x" volver
- if [ $volver == "x" ]
- then
- menuPrincipal
- fi
- }
- function sumarNumeros
- {
- read -p "Ingrese un numero menor que 10" num1
- read -p "Ingrese otro numero menor que 10" num2
- if [[ ($num1<=10)&&($num2<=10) ]]
- then
- echo "La suma es: $($num1+$num2)"
- else
- echo "Alguno de los dos numero es mayor que 10"
- fi
- read -p "Para volver al menu principal ingrese x" volver
- if [[ $volver == "x" ]]; then
- menuPrincipal
- fi
- }
- function calculadora
- {
- opcCalc="y"
- while [ $opcCalc == "y" ]
- do
- echo "1. Suma"
- echo "2. Resta"
- echo "3. Multiplicacion"
- echo "4. Division"
- read calcOpc
- read -p "Ingrese el primer numero" numCalc1
- read -p "Ingrese el segundo numero" numCalc2
- case $calcOpc in
- 1)
- echo "La suma es: $($numCalc1+$numCalc2)"
- ;;
- 2)
- echo "La resta es: $($numCalc1-$numCalc2)"
- ;;
- 3)
- echo "La multiplicacion es: $($numCalc1*$numCalc2)"
- ;;
- 4)
- echo "La division es: $($numCalc1/$numCalc2)"
- ;;
- *)
- echo "Opcion no encontrada"
- ;;
- esac
- read -p "¿Desea hacer otra operacion? [y/n]" opcCalc
- done
- read -p "Para volver al menu principal ingrese x" volver
- if [ $volver == "x" ]
- then
- menuPrincipal
- fi
- }
- function menuPrincipal
- {
- echo "1. Ingresar datos"
- echo "2. Buscar datos"
- echo "3. Eliminar datos"
- echo "4. Sumador (<10)"
- echo "5. Calculadora"
- echo "6. Salir"
- read mainOpc
- case $mainOpc in
- 1)
- ingresarDatos
- ;;
- 2)
- buscarDatos
- ;;
- 3)
- eliminarDatos
- ;;
- 4)
- sumarNumeros
- ;;
- 5)
- calculadora
- ;;
- 6)
- exit
- ;;
- *)
- echo "Opcion no encontrada"
- ;;
- esac
- }
- while [ true ]
- do
- menuPrincipal
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement