Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: SHELL not always correct



On Tue, Oct 21, 2008 at 04:13:23PM -0700, Phil Pennock wrote:
[...]
> work/bash-3.2/variables.c:  temp_var = find_variable ("SHELL");
> work/bash-3.2/variables.c:      temp_var = bind_variable ("SHELL", current_user.shell, 0);
> work/bash-3.2/shell.c:      set_var_read_only ("SHELL");
> 
> Okay, I peeked at variables.c and this comment:
> /* Set $SHELL to the user's login shell if it is not already set.  Call
>    get_current_user_info if we haven't already fetched the shell. */
> decorates set_shell_var() which forcibly claims SHELL for itself.
> 
> Seems rather presumptuous, to claim to child processes that you are the
> user's chosen preferred shell, merely because you're running.
[...]

No, bash doesn't set $SHELL to bash, that would be a bug if it
did, it just sets $SHELL to the user's login shell if it's not
already set which is fine. Here, my login shell is zsh,

$ env -i bash -c 'echo $SHELL'
/bin/zsh

$ env SHELL=/bin/rc bash -c 'echo $SHELL'
/bin/rc

So bash acknowledges my choice, it just sets $SHELL in case it
wasn't set before.

Basically, it's doing the job of login(1). login(1) is the
command that generally initialises $SHELL (that is the user's
shell of choice) to the user's login shell (from the "passwd"
database).

-- 
Stéphane



Messages sorted by: Reverse Date, Date, Thread, Author