ok so i am doing a shell script with the purpose of "safe deleting things", so it's supposed when called "/safedell.sh file1 file2 file3" it will TAR the files and send it to my folder called LIXO. i'm a shell newbie so i will try to explain every step of my code so you guys understand it, so far heres what i have:
#!/bin/bash
#Purpose = Safe delete
#Created on 20-03-2018
#Version 4.0
#START
##Constants##
dir="/home/cunha/LIXO"
#check to see if the imput is a file#
if ! [ -e $1 ]; then`
echo "Not a file!"
exit 0`
fi
###main###
##Cycle FOR so the script accepts multiple file inputs##
for file in "$@"; do
#IF the input file already exist in LIXO#
if [[ -f $dir/$file ]]; then
echo "|||File EXISTS|||"
#IF the input file is newer than the file thats already in LIXO#
if [[ $file -nt $2 ]]; then
echo "file is newer"
fi
else
echo "File doesnt exist, ziping it and moving"
fi
done`
My problem: so i have 2 files in LIXO, teste1.txt and teste2.tar.bz2, my problem is that the shell script that i wrote so far cant find teste2.tar.bz2 when i input teste2.txt
--> input: /safedell teste2.txt
--> output: file doesnt exist, ziping...