Login Shell

From SlackWiki
Jump to: navigation, search


Seeing people give bad advice regarding colored ls output, I figured I better address this problem at the source. If you open a terminal and ls does not give colored output, or the prompt is similar to bash-2.04$ then you are in a non-login shell. This means none of the default profile scripts were sourced.

From the BASH man page:

When  bash  is  invoked  as  an  interactive login shell, or as a non-interactive shell with the
--login option, it first reads and executes commands 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.
The --noprofile option may be used when the shell is started to inhibit this behavior.
When  a  login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it
When an interactive shell that is not a login shell is started, bash reads and executes commands
from  ~/.bashrc,  if  that  file exists.  This may be inhibited by using the --norc option.  The
--rcfile file option will force  bash  to  read  and  execute  commands  from  file  instead  of
When  bash  is  started  non-interactively, to run a shell script, for example, it looks for the
variable BASH_ENV in the environment, expands its value  if  it  appears  there,  and  uses  the
expanded value as the name of a file to read and execute.

You need to configure your terminal to give you an interactive "login shell". A login shell is the same as a login at the console. The default profile and user profile scripts will be sourced. Below are some ways to change how your terminal emulator behaves.


Chances are if you are using Eterm you know what you're doing and not looking at this page. But just for reference, you can envoke a login shell by passing -l or --login-shell at the command prompt. The preferred method is to edit your .cfg file (the default is $PREFIX/share/Eterm/themes/Eterm/theme.cfg) and add login_shell true in the toggles section.

Eterm -l


Edit -> Profiles
Select the profile (Default) and click Edit
Select the Title and Command Tab
Check the box next to Run command as a login shell


There should be a way to do this from some configuration dialog, but I don't use KDE or Konsole, so all I can recommand at this time is the following:

konsole --ls

xterm / rxvt / aterm

xterm -ls
rxvt -ls
aterm -ls

XFCE 4.4 Terminal

Open the XFCE terminal.
Open Edit -> Preferences
Select the "General" icon at the left.
Under "Command", check the box next to "Run command as a login shell"


If you launch screen directly in a X11 terminal emulator, you will notice that using the -ls or equivalent terminal emulator option is not enough to get colored ls output. This is because the terminal emulator is not calling the shell directly, and it's screen who does. screen has a configuration file option to use a login shell and another one to modify the system logs as if you had logged in (read the screen manpage for more details). However, this doesn't seem to be enough to get colored ls output.

Some people avoid these login shell confusions and problems by trying to get the same bash environment no matter how bash ends up being called as an interactive shell. This implies setting the bash prompt (controlled by the environment variable PS1) from the .bashrc user file and either sourcing .bashrc from .bash_profile or making .bash_profile a link to .bashrc. Additionally, you can include the following lines in your .bashrc script to always get colored ls output:

if [ -z "$LS_COLORS" ]; then
    source /etc/profile.d/coreutils-dircolors.sh

These recommendations are the "bad advice" the original author mentioned in the first paragraph.