You are not logged in.
Pages: 1
Hi. I was told I could use aliases to save some typing, so I started checking that out on the internet and then decided to try it myself.
In ~/.bashrc I added
# my aliases:
alias aur="trizen -S"and that one works like a charm.
But when I try to add an alias in /etc/bash.bashrc , that doesn't work. Just for the test I added
alias dld="pacman -S"and tested it with
sudo dld gpickbut it doesn't work. So, what am I doing wrong?
Last edited by rado84 (2019-05-14 21:55:06)
Core i7-4770, GTX 1660 Ti, 32 GB RAM, Arch 6.x LTS, Cinnamon 5.2.7, GDM
Offline
Why would sudo cause /etc/bash.bashrc to be read?
Bash#Configuration_files
Offline
Why would sudo cause /etc/bash.bashrc to be read?
Bash#Configuration_files
On reddit I was told I have to add sudo aliases in the root bash confing file and when I searched for "bash root config", that was the file I found. Unfortunately I lost the post about aliases there, otherwise I would use it as a guide and wouldn't have to ask here.
So, if this is the wrong file, what should I edit for the "sudo dld" alias to work?
Core i7-4770, GTX 1660 Ti, 32 GB RAM, Arch 6.x LTS, Cinnamon 5.2.7, GDM
Offline
Offline
The same as for your normal user, the ~/.bashrc file.
I tried that too. Returns
[rado@anarchy]: ~>$ sudo dld gpick
[sudo] password for rado:
sudo: dld: command not foundwhere alias dld="pacman -S".
Core i7-4770, GTX 1660 Ti, 32 GB RAM, Arch 6.x LTS, Cinnamon 5.2.7, GDM
Offline
You do understand what the ~ means in my previous post?
Using sudo to run an alias directly is an edge case that requires special configuration. First of all does the alias work if you use sudo -i to get a proper root shell?
Offline
Ofcourse I do. As I said in my first post, editing ~/.bashrc for non-root aliases works perfectly. So, yes, I think I know what the ~ is. ![]()
And to answer your second question - no, it doesn't. Doesn't work for ~/.bashrc, doesn't work for the other one in /etc
Last edited by rado84 (2019-05-14 17:40:26)
Core i7-4770, GTX 1660 Ti, 32 GB RAM, Arch 6.x LTS, Cinnamon 5.2.7, GDM
Offline
So, yes, I think I know what the ~ is.
And to answer your second question - no, it doesn't.
The second sentence contradicts the first. The ~ expands to different things depending on which user runs it. When you use sudo, aliases in /home/YOUR_USER/.bashrc are no longer available, only those in /root/.bashrc are available as ~ expands to /root/ for the root user.
However, there is a shortcut to get what you want:
alias sudo='sudo 'This will allow sudo to use your user's aliases.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Apparently you were right - I didn't know that. I thought " ~ " meant "home". As in "/home/[username]".
Thanks for the info, I didn't know there was a bash file in /root.
Core i7-4770, GTX 1660 Ti, 32 GB RAM, Arch 6.x LTS, Cinnamon 5.2.7, GDM
Offline
I thought " ~ " meant "home".
That's exactly what it means.
As in "/home/[username]".
That's just the default location for normal users. The default location for root's ~ is /root.
However, this default can be changed for any user on the system, to get the correct information you can use...
getent passwdOffline
Well, I couldn't get what I wanted to work but I found another way that seems to be working perfectly - in ~/.bashrc :
# my aliases:
alias aur="trizen -S"
alias spac="sudo pacman -S"
alias rmun="yaourt --noconfirm -Rns $(yaourt -Qdttq); yes | yaourt -Scc"All 3 working perfectly. The only condition for that to happen was to use words that the system doesn't know what they are. At first I tried with "install" instead of "spac" but the alias wouldn't work, so I used abbreaviations of the function of the different commands and it worked. The 'spac' is just in case I ever need temporary root rights, altough 'aur' so far does the job fine. 'Rmun' means "remove unnecessary".
Core i7-4770, GTX 1660 Ti, 32 GB RAM, Arch 6.x LTS, Cinnamon 5.2.7, GDM
Offline
Pages: 1