This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [ITA] - base-files


On 14 December 2010 20:41, David Sastre wrote:
> On Fri, Dec 10, 2010 at 06:50:32AM +0000, Andy Koppe wrote:
>> Speaking of /etc/profile.d, it seems wrong to do that from
>> /etc/bash.bashrc. The name of the directory suggests that its content
>> is for login shells only.
>
> Absolutely. I'll try selective sourcing from /etc/profile e.g. bash sources
> *sh, and not *.zsh, and viceversa.

Great.

>> >> > A bash login shell only
>> >> > automatically sources the *profile files, not the *bashrc files. Users
>> >> > have every right to customise their ~/.bash_profile and ~/.bashrc to
>> >> > death, or to just delete them. Or perhaps they didn't have them in the
>> >> > first place because they nominated an existing directory as their home
>> >> > without copying the skel files. So there's no guarantee that ~/.bashrc
>> >> > and /etc/bash.bashrc are sourced by a bash login shell.
>
> This is important. The conclusion of this reasoning is that users'
> personal files (~/.bash{rc,_profile}) shouldn't be trusted at all in
> order to define a system-wide configuration.

I agree.

On a related note, due to the many possible combinations of old and
new startup files, double sourcing is a distinct possibility, e.g. due
to the current /etc/defaults/etc/skel/.bash_profile sourcing
/etc/bash.bashrc. Perhaps this should be addressed with guard
variables similar to include guards in C headers?

>> http://www.gnu.org/software/bash/manual/html_node/Is-this-Shell-Interactive_003f.html
>
> If you propose to check for *i* in $- instead of PS1 (as I'm doing now),
> yeah, it does look more reliable.

Sorry, I hadn't noticed the existing PS1 check. But you're right, the
$- check should be more reliable as PS1 might already be set when the
shell is invoked, e.g. in a Windows environment variable.

>> Zsh sources *profile files in login shells and the *zshrc files in
>> interactive shells, so an interactive login shell sources both.
>
> Not in bash. This is an example of a login shell. I have commented out
> the code that sources /etc/bash.bashrc and ~/.bashrc from
> ~/.bash_profile:
>
> $ grep MY_TEST /etc/profile /etc/bash.bashrc .bashrc .bash_profile
> /etc/profile:MY_TEST=${MY_TEST}:/etc/profile
> /etc/bash.bashrc:MY_TEST=${MY_TEST}:/etc/bash.bashrc
> .bashrc:MY_TEST=${MY_TEST}:~/.bashrc
> .bash_profile:MY_TEST=${MY_TEST}:~/.bash_profile
> $ echo $MY_TEST
> :/etc/profile:/home/dawud/.bash_profile
> $ echo $-
> himBH
>
> (Erm...I just realized know that was _exactly_ your point, was it?)

Yep.

>> Hence
>> stuff that needs to be done once at login (e.g. setting up paths) goes
>> into *profile, and stuff to make an interactive shell comfortable
>> (e.g. prompt and aliases) goes into *zshrc. I think that makes plenty
>> of sense.
>
> It does, indeed.
>
>> Bash isn't going to change in this respect though, so emulating it by
>> /etc/profile sourcing /etc/bash.bashrc and ~/.bash_profile sourcing
>> ~/.bashrc is the next best thing.
>
> I learnt that enabling /etc/bash.bashrc to be sourced as a system-wide *rc
> file can be defined in a header file in the bash sources, and also
> /etc/bash.bash_logout, BTW.

Good find!

The concern I'd have about that is that bash manuals and books don't
tend to mention that possibility, so users might be surprised by it.
Having said that, Ubuntu and Opensuse at least do enable that feature
and change the bash man page accordingly, so that should be plenty of
precedent.

Login shells of course will still only source the *profile files automatically.

>> Wasn't there a patch for doing that switch without forks?
>
> Not that I know of... I'll try to write it down, though.

Found it. Daniel Colascione suggested the following at
http://cygwin.com/ml/cygwin/2010-11/msg00464.html:

- Detect the current shell by examining BASH_VERSION, ZSH_VERSION, and
so on, not by forking for the echo|tr|sed pipeline

Andy


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]