I want to make alias for:
rm -rf *=>#rm -rf *rm *=>#rm *
When I type rm -rf *, I want it to be commented out and not take action.
[Q] General question is can we make generate aliases for the commands with parameters?
I want to make alias for:
rm -rf * => #rm -rf *rm * => #rm *When I type rm -rf *, I want it to be commented out and not take action.
[Q] General question is can we make generate aliases for the commands with parameters?
You cannot create alias with spaces, i.e. something like below is invalid:
alias 'rm -rf *'='#rm -rf *'
But of course you can create alias for commands with parameters:
alias foo='#rm -rf *'
Although from the examples from your question, looks like you want to put # before every rm. To do so, you need to only alias rm:
alias rm='#rm'
If you wanted to only "disable" rm for -rf, then you would need to write a wrapper function:
rm() {
if [ "$1" != "-rf" ]; then
rm $@
fi
}
Can I disable only for
rm -rf *but keeping otherrm -rfif*is not included?
Yes, you can. For example:
rm() {
if [ "$1" != "-rf" ]; then
rm $@
else
shift 1
x="$@"
if [ "$x" != "$(echo *)" ]; then
rm -rf $@
fi
fi
}
rm -rf * but keeping other rm -rf if * is not included?
– alper
Jul 13 '20 at 17:16
zsh: parse error near()'`
– alper
Jul 13 '20 at 17:34
.zshrc (.bashrc is for Bash)
–
Jul 13 '20 at 20:50
rmm() { I don't get the error , but instead if its rm() the parse error shows up
– alper
Jul 14 '20 at 00:00
rm?"
–
Jul 14 '20 at 00:13