[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ~/.profile and ~/.bash_profile aren't executed on login
From: |
Chet Ramey |
Subject: |
Re: ~/.profile and ~/.bash_profile aren't executed on login |
Date: |
Mon, 11 Dec 2017 13:57:52 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 |
On 12/11/17 1:30 PM, Yuri wrote:
> On 12/11/17 06:03, Chet Ramey wrote:
>> Bash, as documented, reads ~/.bash_profile first
>> when it's invoked as a login shell, falling back to ~/.bash_login and
>> ~/.profile if it's not there.
>
>
> I just verified: none of these 3 files are executed by bash when user logs in.
>
> /usr/local/bin/bash is set as user's login shell in 'vipw'. So when this
> user logs in, it must be invoked as a login shell. Is this correct?
Nobody on the list can answer that question. It depends on whether or
not the agent you're using that starts the shell running in a terminal
emulator -- assuming that's the shell instance you're concerned with --
starts it as a login shell. A login shell is what I described previously:
"A login shell is one whose first character of argument zero is a -, or
one started with the --login option."
So it all depends on how the shell is invoked, and you haven't shown how
that is done. In a typical environment, a login shell would end up with
$0 == "-bash", so you'd get something like
$ echo $0
-bash
$
If the shell had been started in this fashion, or using the --login or -l
option at invocation, the `login_shell' shell option (viewable with
`shopt') would be on:
$ shopt login_shell
login_shell on
$
That option is available in bash versions back to bash-2.05b.
So, for example, with the latest version of bash:
$ grep bash_profile ~/.bash_profile
echo this is bash_profile
$ ./bash --version
GNU bash, version 4.4.12(4)-release (x86_64-apple-darwin15.6.0)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ ./bash --login
this is bash_profile
$ shopt login_shell
login_shell on
or
$ ln -s ./bash ./-bash
$ type -a -- -bash
-bash is ./-bash
$ -bash
this is bash_profile
caleb.ins.cwru.edu(2)$ echo $0
-bash
caleb.ins.cwru.edu(2)$ shopt login_shell
login_shell on
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
- Re: ~/.profile and ~/.bash_profile aren't executed on login, (continued)
Re: ~/.profile and ~/.bash_profile aren't executed on login, Yuri, 2017/12/10
- Re: ~/.profile and ~/.bash_profile aren't executed on login, Chet Ramey, 2017/12/10
- Re: ~/.profile and ~/.bash_profile aren't executed on login, Yuri, 2017/12/10
- Re: ~/.profile and ~/.bash_profile aren't executed on login, Geir Hauge, 2017/12/11
- Re: ~/.profile and ~/.bash_profile aren't executed on login, Chet Ramey, 2017/12/11
- Re: ~/.profile and ~/.bash_profile aren't executed on login, Yuri, 2017/12/11
- Re: ~/.profile and ~/.bash_profile aren't executed on login, Greg Wooledge, 2017/12/11
- Re: ~/.profile and ~/.bash_profile aren't executed on login,
Chet Ramey <=
- Re: ~/.profile and ~/.bash_profile aren't executed on login, Greg Wooledge, 2017/12/11
- Re: ~/.profile and ~/.bash_profile aren't executed on login, Chet Ramey, 2017/12/11