basename doesn't deal with multiple files:
NAME
basename - strip directory and suffix from filenamesSYNOPSIS
basename NAME [SUFFIX] basename OPTION...NAME...
Unless the -a option is used (GNU Coreutils):
-a, --multiple support multiple arguments and treat each as a NAME
But thatit would break if the filenames have newlines.
And will fail in your command, since basename -a will return the arguments with new lines
basename "$@"
foo.pdf
bar.pdf
Which breaks the rm command since the arguments passes are separated by new lines.
This code apparently solves the problem
rm $(echo $"$(basename -a "$@")")
but I'm not so sure of its validity.
Yo can then loop over the arguments:
for i in "$@"; do
echo "rm -f /tmp/$(basename "$i")"
rm -f "/tmp/$(basename "$i")"
done
To deal with names with spaces, they must be properly escaped when passed to the script:
$ script.sh "foo bar.pdf"
Or
$ script.sh foo\ bar.pdf