You are not logged in.

#1 2019-05-14 15:08:52

rado84
Banned
From: Sofia, Bulgaria
Registered: 2019-05-12
Posts: 135

[SOLVED] Root aliases not working

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 gpick

but 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

#2 2019-05-14 15:13:50

loqs
Member
Registered: 2014-03-06
Posts: 19,101

Re: [SOLVED] Root aliases not working

Why would sudo cause /etc/bash.bashrc to be read?
Bash#Configuration_files

Offline

#3 2019-05-14 16:59:12

rado84
Banned
From: Sofia, Bulgaria
Registered: 2019-05-12
Posts: 135

Re: [SOLVED] Root aliases not working

loqs wrote:

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

#4 2019-05-14 17:03:09

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] Root aliases not working

The same as for your normal user, the ~/.bashrc file.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#5 2019-05-14 17:08:36

rado84
Banned
From: Sofia, Bulgaria
Registered: 2019-05-12
Posts: 135

Re: [SOLVED] Root aliases not working

Slithery wrote:

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 found

where alias dld="pacman -S".


Core i7-4770, GTX 1660 Ti, 32 GB RAM, Arch 6.x LTS, Cinnamon 5.2.7, GDM

Offline

#6 2019-05-14 17:24:57

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] Root aliases not working

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?


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#7 2019-05-14 17:39:27

rado84
Banned
From: Sofia, Bulgaria
Registered: 2019-05-12
Posts: 135

Re: [SOLVED] Root aliases not working

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. smile

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

#8 2019-05-14 17:48:58

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,530
Website

Re: [SOLVED] Root aliases not working

rado84 wrote:

So, yes, I think I know what the ~ is. smile

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

#9 2019-05-14 20:59:36

rado84
Banned
From: Sofia, Bulgaria
Registered: 2019-05-12
Posts: 135

Re: [SOLVED] Root aliases not working

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

#10 2019-05-14 21:22:46

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] Root aliases not working

rado84 wrote:

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 passwd

No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#11 2019-05-14 21:54:45

rado84
Banned
From: Sofia, Bulgaria
Registered: 2019-05-12
Posts: 135

Re: [SOLVED] Root aliases not working

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

Board footer

Powered by FluxBB