I need to make a recycle bin code using bash my problem is that when i move a file with the same name in the trash folder i just overwrites the previous file can you give me any suggestions on how to approch this problem
Code:
#!/bin/bash
mkdir -p "$HOME/Trash"
touch "$HOME/.info"
if [ $1 = -restore ]; then
argv=($*)
for (( x = 1 ; x < ${#argv[*]} ; x++ ))
do
while read file; do
path=$(basename $file)
if [ "$path" = "${argv[x]}" ]; then
mv $HOME/Trash/${argv[x]} /$file
sed "/$path/d" /$HOME/.info >tmp
mv tmp /$HOME/.info
fi
done < /$HOME/.info
done
else
if [ $1 = -restoreall ]; then
while read file; do
path=$(basename $file)
mv $HOME/Trash/$path /$file
sed "/$path/d" /$HOME/.info >tmp
mv tmp /$HOME/.info
done < /$HOME/.info
mv $HOME/Trash/* /$PWD
else
if [ $1 = -empty ]; then
rm -rfv /$HOME/Trash/*
sed "/$HOME/d" /$HOME/.info >tmp
mv tmp /$HOME/.info
else
args=($*)
for (( i=0 ; i<${#args[*]} ; i++ ))
do
ABSOLUTE=$(readlink -f ${args[i]})
mv $ABSOLUTE $HOME/Trash
echo -e $ABSOLUTE>> /$HOME/.info
done
fi
fi
fi