1

So, this is totally stupid and just an aesthetic problem. I'm looking to simply disable rm, because I'm using more secure functions, so I'm just training myself to stop using rm with messages. I tried the following:

alias rm='echo "No using rm. Use other thing instead."'

and

function rm () {
  echo "No using rm. Use other thing instead."
}

But when I run rm -rf testfolder/ the output is:

No using rm. Use other thing instead. -rf testingfolder/

Is there a way to have it not put the -rf testingfolder/ at the end?

EDIT: For some reason, the function just wasn't working correctly, and I needed to restart my computer to make it work. Really odd.

1
  • 2
    function definition should eliminate the arguments. make sure you unalias rm definition and just use the function. Commented Mar 1, 2019 at 21:06

1 Answer 1

4

Just get rid of the alias.

Aliases only replace the thing they are aliasing (keeping all other args), whereas functions will consume all args whether or not you actually do anything with them.

Sign up to request clarification or add additional context in comments.

4 Comments

To add to this: if you have both an alias an a function defined, the alias takes precedence, so it doesn't make sense to have both. If you add ; # to the end of the alias, the arguments are ignored, but using a function is simpler.
Using a function might break scripts that depend on rm functioning normally (whether the function would be defined in scripts depends on exactly where you define it). An alias would not cause this problem, since aliases are disabled (by default) in scripts.
Yeah, that's why I switched to the function, thinking that. I did remove the alias when I added the function. It turns out, I needed to restart my computer before the function was treated correctly. It was odd.
@JaimeWissner Removing the alias from your .bashrc won't remove it from any shells that already had the alias defined. Restarting your computer works, or you can use unalias rm, or you can restart any shells you had running at the time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.