113 lines
2.1 KiB
Bash
Executable File
113 lines
2.1 KiB
Bash
Executable File
#!/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
|