Description of problem: privileged-access requiring aliases fail when executed as sudo-user. Version-Release number of component: bash.x86_64 4.4.19-2.fc28 @fedora Steps to Reproduce in terminal as sudo-user: 1. Edit hidden bashrc file, 'gedit ~/.bashrc', then add on their own lines '# Remove packages', 'alias remo='dnf -y remove''. Quit terminal. 2. $ su -c 'remo dnfdragora' Password: (for root) bash: remo: command not found 3. $ sudo remo dnfdragora [sudo] password for yk: sudo: remo: command not found Actual results: The use of privileged-access requiring aliases fail when subsequent commands are executed as sudo-user. Expected results: Such aliases to be excecutable as sudo-user as well.
Aliases are expanded on the begin of your command line only. So if your command line starts with 'su' or 'sudo' and none of them is an alias, no other aliases are expanded. bash probably does not support what you are looking for but you can try zsh, which supports global aliases: % alias -g remo='dnf -y remove' % sudo remo ... Global aliases expand anywhere on the command line. Please use it with care.
Existing entry is replaced by '% alias -g remo='dnf -y remove''. Messages resulting from implementation are: – 'bash: fg: no job control' (displayed when opening the terminal). – $ source ~/.bashrc bash: fg: %: no such job
Please re-read comment #1. The command to define global alias will not work in bash. I was talking about zsh (another shell interpreter). Moreover, the '%' sign was not supposed to be typed at all. It just denotes the command prompt ('%' is the default prompt in zsh, similar to '$' in bash).
Since comment #3 completed comment #1, solution is clear enough. Thanks