Bug 1569893

Summary: Privileged-access requiring aliases fail when executed as sudo-user.
Product: [Fedora] Fedora Reporter: ricky.tigg
Component: bashAssignee: Siteshwar Vashisht <svashisht>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: unspecified    
Version: 28CC: admiller, kasal, kdudka, svashisht
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-04-20 08:37:39 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description ricky.tigg 2018-04-20 08:08:15 UTC
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.

Comment 1 Kamil Dudka 2018-04-20 08:37:39 UTC
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.

Comment 2 ricky.tigg 2018-04-20 11:44:25 UTC
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

Comment 3 Kamil Dudka 2018-04-20 12:11:05 UTC
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).

Comment 4 ricky.tigg 2018-04-20 12:25:13 UTC
Since comment #3 completed comment #1, solution is clear enough. Thanks