/etc/skel/.profile does not detect bash properly

Bug #1099987 reported by Alec Warner
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
bash (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

So if I run bash in posix mode or as /bin/sh.

antarus@goats5 /etc/skel $ env -i /bin/sh -c 'echo $BASH_VERSION'
4.2.24(1)-release
antarus@goats5 /etc/skel $ env -i bash --posix -c 'echo $BASH_VERSION'
4.2.24(1)-release

This means when lightdm-session-wrapper sources the users $HOME/.profile (created from /etc/skel) it will also sources their $HOME/.bashrc. lightdm-session-wrapper runs as posix sh, and not bash. Sourcing a .bashrc as posix sh does not work well.

antarus@goats5 ~/antarus $ /bin/sh
sh-4.2$ source ~/.bashrc
sh: `break-posix-sh': not a valid identifier
antarus@goats5 ~/antarus $ grep 'break-posix-sh' ~/.bashrc
function break-posix-sh() {

Functions cannot have dashes in them in posix, but can in bash, for example.

If you replace the .profile login with something like:

if ! shopt -oq posix; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

It seems to work properly.

DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.1 LTS"
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04

antarus@goats5 ~/antarus $ apt-cache policy bash
bash:
  Installed: 4.2-2ubuntu2
  Candidate: 4.2-2ubuntu2
  Version table:

If lightdm cannot source my .bashrc, I cannot login. Also, thousands of my users cannot login.

-A

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in bash (Ubuntu):
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.