Note: If you googled this by the title of this question, don't use this script unless you know what it is supposed to do.
This is a script in bash
3+ that I have used for long for preventing rm *
and rm -rf *
from accidentally invoked and removing important files by mistake. I put it in my ~/.bash_aliases
.
alias rm='set -f;rm'
rm(){
if [[ "$-" == *i* ]]
then
if [ "$1" = "*" ] || [ "$2" = "*" ] || [ "$1" = "./*" ] || [ "$2" = "./*" ]
then
echo "Abort: refusing to remove *, please go to the parent folder and do rm <folder_name>/*" 1>&2
set +f
return 1
fi
fi
set +f
/bin/rm -i $@
}
set +f
I would like to know whether there are any vulnerabilities and whether it can be improved.