I am trying to create an alias for the rm command in the /root/.bashrc file on a VirtualBox Redhat VM (running RHEL 9). I cannot get it to work properly. This is an excerpt of my .bashrc file:
alias rm='printf "rm: cannot remove %s: Permission denied\n" "$@" && w >> /tmp/logfile_20090204_001.log'
sudo() {
if [[ "$1" == "rm" ]]; then
for file in "${@:2}"; do
printf "rm: cannot remove %s: Permission denied\n" "$file"
done
w >> /tmp/logfile_20190204_002.log
else
command sudo "$@"
fi
}
I reload it with . /root/.bashrc. The result I get when using rm is rm: cannot remove : Permission denied (no file name). I have tried replacing printf with echo, switching the single and double quotes and modifying the bash_aliases file instead of the .bashrc file, and nothing seems to work. How can I get this alias to print my file name (with and without sudo)?
Thank you in advance for your help!