Linux/Unix Shell Scripting - Problema con script

 
Vista:

Problema con script

Publicado por Rayban20 (1 intervención) el 02/11/2005 23:12:22
No funciona la opcion borrar. Alguien me exa un cable??

condicion=0
while [ $condicion -eq 0 ]
do
echo
echo "¡Bienvenido a la agenda!"
echo
echo "L. Listar notas."
echo "A. Anyadir notas."
echo "B. Borrar una nota."
echo "S. Salir del programa."
echo
echo "¿Que desea hacer?:"
read opcion

case $opcion in

L)
if [ -f agenda.dat ]
then
echo "Introduzca la fecha de las notas que desea ver:"
read dia
grep $dia agenda.dat | cut -f2,3 -d: agenda.dat >> temporal
sort -n agenda.dat > temporal
echo
echo "Fecha:Hora:Nota"
cat temporal|more
rm temporal
else
echo "No existe el fichero agenda.dat, añada primero alguna nota"
fi
;;
A)
echo "Elija la opcion que quiera:"
echo "1-Anyadir nota:"
echo "2-Modificar nota:"
read opcion
echo
case $opcion in
1)
echo "Introduzca la nota a anyadir:"
read nota
echo $nota >>agenda.dat
;;
2)
if [ -f agenda.dat ]
then
echo "Introduzca la fecha de la nota a modificar:"
read dia
grep $dia agenda.dat >> temporal
control=`cat temporal|wc -l`
if [ $control -eq 0 ]
then
echo "No exite ninguna nota con esa fecha."
else

echo "Introduzca la hora de la nota a modificar:"
read hora
lin=`cat agenda.dat | wc -l`
bucle=1
num=1
nota=`grep $dia:$hora agenda.dat`
while [ $bucle -le $lin ]
do
echo "primero"
var=`head -$bucle agenda.dat | tail -1`
if [ "$var" = "$nota" ]
then
echo "segundo"
until [ $num -eq $lin ]
do
echo "tercero"
if [ $num -eq $bucle ]
then
num=`expr $num + 1`
else
head -$num agenda.dat|tail -1 >>temporal
num=`expr $num + 1`
fi
done
rm agenda.dat
mv temporal agenda.dat
else
bucle=`expr $bucle + 1`
fi
done
echo "Introduzca la nota modificada:"
read nota
echo "$dia:$hora:$nota">> agenda.dat
fi
else
echo "No existe el fichero agenda.dat priemro anyada alguna nota."
fi ;;
*)
echo "Opcion incorrecta."
;;
esac
;;

B)
if [ -f agenda.dat ]
then
echo "Introduzca la fecha de la nota a borrar:"
read dia
echo "Introduzca la hora de la nota a borrar:"
read hora
lin=`cat agenda.dat | wc -l`
bucle=1
num=1
nota=`grep $dia:$hora agenda.dat`
while [ $bucle -le $lin ]
do
echo "primero"
var=`head -$bucle agenda.dat | tail -1`
if [ "$var" = "$nota" ]
then
echo "segundo"
until [ $num -eq $lin ]
do
echo "tercero"
if [ $num -eq $bucle ]
then
num=`expr $num + 1`
else
head -$num agenda.dat|tail -1 >>temporal
num=`expr $num + 1`
fi
done
rm agenda.dat
mv temporal agenda.dat
else
bucle=`expr $bucle + 1`
fi
done
if [ "$var" = "$nota" ]
then
echo "cuarto"
echo "La nota ha sido eliminada."
else
echo "La nota no existe, no se puede eliminar."
fi
else
echo "No existe el fichero agenda.dat introduce primero alguna nota."
fi;;
S)
condicion=1
echo
echo "Hasta luego!!";;
*)
echo "Error, opcion incorrecta."
echo ;;
esac
done
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder