I have two aliases:
alias rm='python my/rm/script.py '
alias docker='sudo docker '
The problem is that when running the statement $ docker rm ARGS
the keyword rm
is being expanded as alias and docker complains that 'python' is not a docker command.
I looked for a couple of solutions. One solution is to use command
keyword. Another is to use shopt
to toggle alias expansion. I'm unable to put them to good use.
Both of these are not working out for me:
alias docker='shopt -u expand_aliases; sudo docker '
alias docker='command sudo docker '
Unalias works:
alias docker='unalias rm; sudo docker '
The problem with unalias is that after a while I'm gonna forget that my rm alias is no longer in place in a running shell environment wherever my docker commands have been executed. As a result me using rm
on a file would instantly erase it, in contrast to my python script which acts as a safetynet and moves to-be-deleted files in Trash. I want to avoid getting into this situation where I mistakenly end-up using GNU rm command and not my rm alias, and that's why I don't want to use unalias.
Another solution is to let go of docker alias. The downside is that I'd have to write sudo
keyword for every useful docker command I want to execute. That is a chore which I was avoiding using the alias for docker.
One more solution is to escape rm keyword like this:
docker \rm ARGS
This works. But I'm hoping for a fire-and-forget solution here so that I can execute my docker commands naturally without concerning about anything else.
Given the above constraints, how do I use alias for both rm and docker but prevent rm
keyword being expanded as alias in docker commands?