Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE
uname output: Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.41-2+deb7u2
x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu
Bash Version: 4.2
Patch Level: 45
Release Status: release
Description:
Login shell not setting HOME variable when using -l option,
but is set when using - as argument zero. This is not
differentiated in the documentation,
"A login shell is one whose first character of argument zero
is a -, or one started with the --login option."
therefore I assume it is a bug.
I would expect consistent behavior between the two methods
of acquiring a login shell.
Repeat-By:
root@debian:~# unset HOME
root@debian:/root# /bin/bash -l
root@debian:/root# cd
bash: cd: HOME not set
root@debian:/root# logout
root@debian:/root#
root@debian:/root# argv0 /bin/bash -
root@debian:~# cd
root@debian:~# logout
root@debian:/root#
root@debian:/root# argv0 /bin/bash - -l
root@debian:/root# cd
bash: cd: HOME not set
root@debian:/root# logout
root@debian:/root#
Fix:
The line numbers I am referring to below are of revision
f281b8f4f8936b2713966274d9f8508a9f0910e4.
When we use the -l option, the value of login_shell is
incremented and then inverted in line 478 of shell.c, and
line 486 of variables.c relies on the value being equal to
1, which I believe is wrong.
As a reference, the only reliance on the value being
negative is in line 1047 of shell.c.
Patch:
diff --git a/patchlevel.h b/patchlevel.h
index d959843..f5e2525 100644
--- a/patchlevel.h
+++ b/patchlevel.h
@@ -25,6 +25,6 @@
regexp `^#define[ ]*PATCHLEVEL', since that's what
support/mkversion.sh
looks for to find the patch level (for the sccs version string). */
-#define PATCHLEVEL 45
+#define PATCHLEVEL 46
#endif /* _PATCHLEVEL_H_ */
diff --git a/variables.c b/variables.c
index 7bb850f..c90b8dd 100644
--- a/variables.c
+++ b/variables.c
@@ -483,7 +483,7 @@ initialize_shell_variables (env, privmode)
bind_variable ("OPTERR", "1", 0);
sh_opterr = 1;
- if (login_shell == 1 && posixly_correct == 0)
+ if (login_shell && posixly_correct == 0)
set_home_var ();
/* Get the full pathname to THIS shell, and set the BASH variable