Why do I need to run "/bin/bash --login"

36,580

Solution 1

It sounds like the environment necessary for the system to find the installed ruby components is specified in a file that only gets read for login shells. The bash manual page has this to say about the difference between login shells and non-login shells:

INVOCATION
   A  login shell is one whose first character of argument zero is a -, or
   one started with the --login option.

and

   When bash is invoked as an interactive login shell, or as a non-inter‐
   active shell with the --login option, it first reads and executes  com‐
   mands  from  the file /etc/profile, if that file exists. After reading
   that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
   in  that order, and reads and executes commands from the first one that
   exists and is readable.  

whereas

   When an interactive shell that is not a login shell  is  started,  bash
   reads  and  executes  commands  from /etc/bash.bashrc and ~/.bashrc, if
   these files exist. 

Hence if the ruby environment variables are in /home/rails/.profile or /etc/profile for example, they will be added to the shell environment

  • by explicitly invoking a login shell using su -l rails or su --login rails or the shorthand su - rails
  • when user rails logs in via SSH
  • by starting a subshell as bash --login after login

If you want the ruby environment to be set regardless of how you switch to user rails, you could move the relevant variable definitions to the user's ~/.bashrc instead.

Solution 2

I know that this question was asked 2 years ago, but in case if somebody (like me) still facing it: @steeldriver is right -- you are missing something in your bashrc which you do have in one of those 3 files. In my case I just needed to add this line into mine ~/.bashrc:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Share:
36,580

Related videos on Youtube

Ole Henrik Skogstrøm
Author by

Ole Henrik Skogstrøm

Updated on September 18, 2022

Comments

  • Ole Henrik Skogstrøm
    Ole Henrik Skogstrøm over 1 year

    I have just setup a new Ubuntu 13.10 server with ruby 2.1.1 installed through rvm.

    The problem is that whenever I switch to the user "rails" (the user I installed ruby and rails with) I have to run /bin/bash --login before Ubuntu recognises that ruby, rails or rvm is installed.

    Hope someone knows:

    1. What does the command above do?
    2. why do i need to run it?
    3. and what can i do to solve it once and for all? :)

    Any help is appreciated!

    • steeldriver
      steeldriver about 10 years
      How are you switching to user "rails" (plain su? or something like su -l or su --?). What is the login shell for user "rails"? Did you modify the user's PATH variable and if so in which file (~/.profile or ~/.bashrc or ~/.bash_profile or ... ?)
    • Ole Henrik Skogstrøm
      Ole Henrik Skogstrøm about 10 years
      I see now that the problem only occurs when i use the su command to switch from root to the rails user. When i ssh in with the rails user this problem does not happen. However i would still like to know what /bin/bash --login does. :)
  • Ole Henrik Skogstrøm
    Ole Henrik Skogstrøm about 10 years
    Hmmm, ok, i think i need an example of the last part. I'm new to linux and ubuntu. What are the relevant variable definitions? In what file are they written now? could you give me an example? This is a bit to theoretical.