1

On my GNU/Linux Debian 9, I would like to run:

sudo -s source /home/UserName/.bashrc

Respectively I would like to define an alias like that one, let's name it su2.

I can't manage to run a command like that.

The command runs successfully, but not as to my expectations.

Invoking it does not seemingly do anything, not even make me root.

I am confused as to why that is.

So what I want it to do:

  1. root me like:

    sudo -s
    
  2. source my personal bashrc and aliases like:

    source /home/UserName/.bashrc
    source /home/UserName/.bash_aliases
    

That's all.

0

1 Answer 1

4

source is a shell built-in, so you can’t run it via sudo. The following should work:

sudo bash --rcfile /home/UserName/.bashrc

.bash_aliases is typically processed by .bashrc (it’s not supported by Bash by default), with something like

if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases; fi

To handle your aliases correctly, you can replace this with

if [ -f /home/UserName/.bash_aliases ]; then . /home/UserName/.bash_aliases; fi
4
  • 1
    Doesn’t your .bashrc take care of that? Nov 2, 2017 at 12:27
  • ^If not just use && or ; e.g sudo bash --rcfile /home/UserName/.bashrc ; sudo bash --rcfile /home/UserName/.bash_aliases Nov 2, 2017 at 12:29
  • @Hunter think about that, it can’t work... Nov 2, 2017 at 12:31
  • @Vlastimil the simplest solution there is for you to change that in your .bashrc. Nov 2, 2017 at 12:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .