From 2e92eaa0d19661743fe9d96e767879e4d1c4e393 Mon Sep 17 00:00:00 2001 From: raul Date: Wed, 15 Jan 2025 17:56:29 +0100 Subject: [PATCH] Add new exercise --- class/scripts2/.gitignore | 1 + class/scripts2/script2.sh | 112 ++++++++++++++++++++++++++++++++++++++ guess_number.sh | 1 - 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 class/scripts2/.gitignore create mode 100755 class/scripts2/script2.sh diff --git a/class/scripts2/.gitignore b/class/scripts2/.gitignore new file mode 100644 index 0000000..e036ec4 --- /dev/null +++ b/class/scripts2/.gitignore @@ -0,0 +1 @@ +BANCO.txt diff --git a/class/scripts2/script2.sh b/class/scripts2/script2.sh new file mode 100755 index 0000000..9745e5b --- /dev/null +++ b/class/scripts2/script2.sh @@ -0,0 +1,112 @@ +#!/bin/bash +FILE="./BANCO.txt" + +pause() { + read -p "Pulse enter para continuar: " +} + +list() { + echo -e "\n----------------------------------" + cat $FILE | sort -t ';' -k3 + echo -e "----------------------------------\n" +} + +fileCheck() { + if [[ ! -f "$FILE" ]]; then + touch ./BANCO.txt + fi +} + +addMove() { + read -p "Nombre: " NOMBRE + #read -p "Fecha: " FECHA + FECHA=$(date -u +%Y-%m-%d_%H-%M-%S) + read -p "Importe: " IMPORTE + read -p "Descripción: " DESCRIPCION + NUM_MOV=$(findFreeID) + echo "$NUM_MOV;$NOMBRE;$FECHA;$IMPORTE;$DESCRIPCION" >> $FILE +} + +findFreeID() { + COUNT=0 + while true; do + LINE=$(grep "^$COUNT;*" $FILE) + if [ -z $LINE ]; then + echo $COUNT + break + fi + let COUNT++ + done +} + +searchMove() { + ID=$1 + echo -e "\n----------------------------------" + grep "^$ID;*" $FILE + echo -e "----------------------------------\n" +} + +search() { + read -p "ID de movimiento a buscar: " MOV + searchMove $MOV +} + +listMoves() { + command ... +} + +calcTotal() { + command ... +} + +deleteMove() { + command ... +} + +status() { + clear + cat <<'END_CAT' ++-----------------------------------------------------------------+ +| MENU DEL BANCO | ++-----------------------------------------------------------------+ +| a - Añadir un movimiento bancario. | +| b - Buscar un movimiento bancario por NUM_MOV. | +| l - Listar todos los movimientos bancarios ordenados por fecha. | +| t - Calcular el saldo total de la cuenta. | +| d - Eliminar movimiento bancario. | +| s - Salir del programa. | ++-----------------------------------------------------------------+ +END_CAT +} + +main() { + fileCheck + while true; do + status + read -p "Opción: " OPT + case "$OPT" in + "a") + addMove + ;; + "b") + search + pause + ;; + "l") + list + pause + ;; + "a") + command ... + ;; + "a") + command ... + ;; + "s") + exit + ;; + esac + done +} + +main diff --git a/guess_number.sh b/guess_number.sh index d45ce94..4d8e5c9 100755 --- a/guess_number.sh +++ b/guess_number.sh @@ -1,6 +1,5 @@ #!/bin/bash RANDOM_NUM=0 -ACTION_TO_TAKE="" ATTEMPTS_NUM=7 POOL_NUM=100