Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 104491 - bashrc incorrect check for login shell
bashrc incorrect check for login shell
Product: Red Hat Linux
Classification: Retired
Component: setup (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Bill Nottingham
David Lawrence
Depends On:
  Show dependency treegraph
Reported: 2003-09-16 08:55 EDT by Steve Stavropoulos
Modified: 2014-03-16 22:38 EDT (History)
1 user (show)

See Also:
Fixed In Version: 2.5.34-1
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-09-23 01:20:37 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
attachment removed. Comment #1 has a better fix. (427 bytes, text/plain)
2004-02-28 18:44 EST, Landon Curt Noll
no flags Details

  None (edit)
Description Steve Stavropoulos 2003-09-16 08:55:16 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030807

Description of problem:
 When you start a shell that is not a login shell (starting gnome-terminal with
default settings for example) then the /etc/bashrc fails to understand that this
is not a login shell and the /etc/profile.d/*.sh files are not sourced as they
should be. One of the consequences of this is that ls doesn't have colors.
 The problem is in every redhat version from at least 6.2 till 9.
A patch to fix this is included below.

--- bashrc_original     Tue Sep 16 14:52:11 2003
+++ bashrc      Tue Sep 16 14:51:59 2003
@@ -39,7 +39,7 @@
     [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
-    if [ "x$SHLVL" != "x1" ]; then # We're not a login shell
+    if [ `shopt login_shell | cut -f 2` == "off" ]; then # We're not a login shell
         for i in /etc/profile.d/*.sh; do
            if [ -r "$i" ]; then
                . $i

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Start gnome-terminal
2. run alias

Actual Results:  nothing. No aliases are set.

Expected Results:  The correct output would be something like:
alias l.='ls -d .[a-zA-Z]* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

Additional info:
Comment 1 Steve Stavropoulos 2003-10-13 07:25:26 EDT
An improvement over the previous patch would be to replace the if line with:
 if ! shopt -q login_shell; then # We're not a login shell
That way no cut is needed and we have a cleaner solution.
Comment 2 Landon Curt Noll 2004-02-28 18:42:24 EST
I would recommend that you use the $- variable to determine
if the shell is interactive.  This will save in having to
execute progs and form a pipe.

See the my patch for details.
Comment 3 Landon Curt Noll 2004-02-28 18:44:43 EST
Created attachment 98128 [details]
attachment removed.
Comment #1 has a better fix.

My patch works for RH9, Fedora, and RHEL3.
Comment 4 Landon Curt Noll 2004-02-28 19:04:05 EST
I'll withdraw my comments #2, #3 and the attachment.

I see that the sub-submitter is looking for login shell, not
interactive shells.  The use of if ! shopt -q login_shell; then ...
is just as good.  Therefore I recommend the patch:


as suggested in comment #1.
Comment 5 Landon Curt Noll 2004-02-28 19:07:08 EST
Comment on attachment 98128 [details]
attachment removed.
Comment #1 has a better fix.
Comment 6 Landon Curt Noll 2004-02-28 19:10:15 EST
Comment on attachment 98128 [details]
attachment removed.
Comment #1 has a better fix.

Patch removed.
Comment 7 Bill Nottingham 2004-09-23 01:20:37 EDT
Added in 2.5.34-1. 
Comment 8 Tim Waugh 2005-08-15 04:45:30 EDT
This seems to break things: see bug #165873.

Note You need to log in before you can comment on or make changes to this bug.