Add new exercise

This commit is contained in:
raul 2025-01-15 17:56:29 +01:00
parent 48b53ecf99
commit 2e92eaa0d1
Signed by: raul
GPG Key ID: C1AA797073F17129
3 changed files with 113 additions and 1 deletions

1
class/scripts2/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
BANCO.txt

112
class/scripts2/script2.sh Executable file
View File

@ -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

View File

@ -1,6 +1,5 @@
#!/bin/bash
RANDOM_NUM=0
ACTION_TO_TAKE=""
ATTEMPTS_NUM=7
POOL_NUM=100