Bug 104491

Summary: bashrc incorrect check for login shell
Product: [Retired] Red Hat Linux Reporter: Steve Stavropoulos <steve>
Component: setupAssignee: Bill Nottingham <notting>
Status: CLOSED RAWHIDE QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: medium    
Version: 9CC: rvokal
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: 2.5.34-1 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-09-23 05:20:37 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Attachments:
Description Flags
attachment removed. Comment #1 has a better fix. none

Description Steve Stavropoulos 2003-09-16 12:55:16 UTC
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 @@
     esac
     [ "$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:
Always

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 11:25:26 UTC
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 23:42:24 UTC
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 23:44:43 UTC
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-29 00:04:05 UTC
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:

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=104491#c1

as suggested in comment #1.

Comment 5 Landon Curt Noll 2004-02-29 00:07:08 UTC
Comment on attachment 98128 [details]
attachment removed.
Comment #1 has a better fix.

Comment 6 Landon Curt Noll 2004-02-29 00:10:15 UTC
Comment on attachment 98128 [details]
attachment removed.
Comment #1 has a better fix.

Patch removed.

Comment 7 Bill Nottingham 2004-09-23 05:20:37 UTC
Added in 2.5.34-1. 

Comment 8 Tim Waugh 2005-08-15 08:45:30 UTC
This seems to break things: see bug #165873.