An alias is a shell function, and nice
is an external program:
$ type nice nice is hashed (/usr/bin/nice)
This is a nice
program that runs the command passed as an argument by calling the C execve
function, so all arguments for it must be evaluated before being called.
So, it would be better not to use an alias and just put the whole command needed there, but if you really want it, you can try something like this:
$ nice -10 `alias list | sed "s/^\(alias \)\?[^=]\+='//; s/'$//;"`
alias list
prints the alias list
definition in the format alias list='ls'
(or list='ls'
if it is /bin/sh
), so I did some sed replacements there to get only the command that it extends.
If you are sure that you are using only bash
, you can use ${BASH_ALIASES[list]}
instead, as noted in the comments:
$ nice -10 ${BASH_ALIASES[list]}
source share