I have a shell script that needs to delete the file names from the /tmp directory. The file names must be detected from a list of file names passed to my script.
./deletetmpfiles.sh /var/moht/test1.pdf /var/shif/log/test4.pdf
Any number of files can be passed as arguments to the deletetmpfiles.sh script.
Considering the above example.
My script should delete /tmp/test1.pdf & /tmp/test4.pdf
Below is what I attempted.
echo "Deleting the following files as they got printed: $@"
cd /home/system/bey.de/invoices/send4print
if [ $? -eq 0 ]; then
echo "Deleting the following on the server: $@"
echo "rm -f /tmp/$(basename $@)"
rm -f /tmp/$(basename $@)
fi
But it deletes only the first file from /tmp i.e /tmp/test1.pdf and misses deleting the remaining files.
Can you please suggest?
basenamedoesn't deal with multiple files.