Cereal Killer
Cereal Killer

Reputation: 3414

Add source to bash

In my Debian server, all users run sh, but root runs bash; when i start a ssh connection, i log in with my personal account that does not have root privileges; i've installed rvm and I want to use it as root because using it from my personal user, it fails installing everything since the user does not have permissions to write where is neeeded; so everytime i need to type

source /usr/local/rvm/bin/rvm

before being able to use rvm; to avoid typing source command everytime, in sh i know i can put the command in /etc/profile file; is there something similar for bash?

I've tried to add "echo aaa" to /etc/profile, to see what happen; when i login as my personal user, i get the "aaa" output; but when i type su and login as root, nothing happens... I think that when i use "su" command and login as root, the /etc/profile is not read

The same happens after installing by rvm a ruby release: I setup the default ruby version (as root) and then the ruby command is available for my personal user (but if i do "su" again and try to type "ruby -v" as root, i get "command not found"

Another thing: after login with my personal user, the rvm command is available; after typing "su", no more; if I add the source command to /etc/profile, once login is done with personal user, i can see a screen output from rvm (some kind of doc); the same happens after using the source command as root

Upvotes: 0

Views: 3577

Answers (2)

awiseman
awiseman

Reputation: 5714

/etc/bash.bashrc is the global config for bash, though /etc/profile is usually sourced by bash as well.

You may need to run the command with 'sudo' in order to actually run it as root. I believe the shell config scripts for any shell will run as the user that is launching the shell. If you prefer, you could also run the binary in an 'sh' shell as well:

sudo /bin/sh -c /usr/local/rvm/bin/rvm

Here's some more info, just in case: https://wiki.debian.org/sudo

Upvotes: 0

that other guy
that other guy

Reputation: 123490

bash -- being an extension of sh -- also reads /etc/profile.

bash specific alternatives include ~/.bash_profile for login shells, and ~/.bashrc and for non-login shells.

Upvotes: 2

Related Questions