Help with database deleting data!!!

Hi, I'm new to programming in shell and I wanted to make a simple database on shell script but I'm having trouble in deleting data. I would apreciate any kind of help. Thank you in adavanced.

Hi Lina_14,

In read file1 and cat $file variables are different and program seems to hang because cat waits for input from keyboard. I had to remove it and the sixth option (6.Delete file) worked.

1 Like

The problem is that when I record data, I want to delite not only the file but also the data from the database :/, I would apreciate any kind of help.

i="y"
echo "Enter name of database "
read db
while [ $i = "y" ]
do
clear
echo "1.Enter id "
echo "2.Display current dir"
echo "3.Listing the dir"
echo "4.Make a dir"
echo "5.Copy a file"
echo "6.Rename file"
echo "7.Delete file"
echo "8.Edit file"
echo "9.Shto regjistrim"
echo "10.Exit"
echo "Enter your choice"
read ch
case $ch in

1)echo "Enter id "
read id
grep -i "$id" $db;;
2)echo "Current Dir is : "
  pwd;;
  3)echo "Directories are"

    ls;;
    4)echo "Enter dir name to create"
     read d
             mkdir $d
                 echo $d" Dir is created";;
             5)echo "Enter filename from copy"
              read f1
               echo "Enter filenm2 to be copied"
                read f2
                    #cat $f1 > $f2
                        cp $f1 $f2
                            echo $f2" is copied from "$f1;;
                        6)echo "Enter file name to rename"
                         read f1
                          echo "Enter new name of file"
                           read f2
                                   mv $f1 $f2
                                       echo $f1" is renamed as "$f2;;
                                   7)echo "Enter any filenm to be delete"
                                    read f1
                                            rm $f1
                                                echo $f1" is deleted";;
                                            8)echo "Enter any file to be editing "
                                             read f1
                                                     vi $f1;;
9)echo "Enter the name"
read kdi
echo �$kdi� > dbkodi
cat dbkodi
echo "Enter the profesion:"
read tpi
echo �$tpi� > dbtitulli
cat dbtitulli
echo "Enter the school "
read ept
echo �$ept� > dbemri_piktorit
cat dbemri_piktorit
echo "Enter the class"
read cmm
echo �$cmm� >dbcmimi
cat dbcmimi
echo "$kdi $tpi $ept $cmm">>$db;;

                                                 10)echo "Have a nice time"
                                                 exit;;
                                                 *)echo "Invalid choice entered";;
                                                 esac
                                                 echo "Do u want to continue ? "
                                                 read i
                                                 if [ $i != "y" ]
                                                 then
                                                 exit
                                                 fi
                                                 done

change these

.................................
.......................
read db
if [ -z "$db" ] ; then echo "DB name is empty!! " ; exit 1 ; fi
.................................
.......................
cp $f1 $f2
[ $? -eq 0 ] && echo "$f2 is copied from $f1";;
.................................
.......................
mv $f1 $f2
[ $? -eq 0 ] && echo "$f1 is renamed as $f2";;
.................................
.......................
rm $f1
[ $? -eq 0 ] && echo $f1" is successfully deleted";;
.................................
.......................

if [ $c != "y" ]
then
exit
fi
done
1 Like

Example when I put records on the database and then i want to delet a line based on ID given, in terminal its says "Data deleted" but in database still exist. Thank you for improving my code.

try using this code where you are deleting files-

/bin/rm -f <dir_name/file_name> 2>> output.err 1>>output.log

and check the log files

a little correction about my writes

........
esac
         echo "Do u want to continue ? "
         read c
if [ $c != "y" ]
then
exit
fi
done

and i can not see the delete records(ID) from database in your code ? which (choice )one ? is it 7 ?

1 Like
10)echo "Enter Id"
read id
sed '/$id/d' $db > dbs1
grep -v $id $db > dbs1
echo "Record deleted !"
cat dbs1;;

Sorry made some modification on the primary code and forgot to update here, thank you for helping with deleting file its works very well now :slight_smile: and thank you for your precios help.