I have alias rm='rm -i' in my ~/.bashrc file (I've just learned it is considered bad practice by some).

It seems the alias is not taken into account when running it with nice:

bli@naples:~$ touch test
bli@naples:~$ rm test
rm: remove regular empty file 'test'? n
bli@naples:~$ nice rm test

Why is that so?


By default, nice is an external command:

$ command -v nice

This means it has no knowledge of aliases, which are a shell feature:

$ alias foo='echo hello'
$ foo
$ nice foo
nice: foo: No such file or directory

However there is a feature of the shell that allows aliases to also expand further aliases. You end the expansion with a space.

$ alias nice='/usr/bin/nice '

Spot that space at the end; it's important.


$ nice foo
$ command -v nice
alias nice='/usr/bin/nice '

Any external command can be wrapped with an alias like this if you want the shell to do alias expansion.


nice is not bash. bash substitutes the aliases while nice doesn't. Using aliases is a bash-only feature. And zsh, ksh, ...so: shell feature. nice is not a shell.


nice will use one of the exec(3) system calls, which know nothing about shell aliases. Global alias replacement can be done in some shells (e.g. ZSH) though I consider it such a massive footgun that I only mention it as a warning to the next 10 generations:

% alias -g rm='rm -i'
% echo hi rm there
hi rm -i there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.