[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: User's bin path not recognised in login script



On Tue 22 Mar 2016 at 22:35:32 (+0000), Russell Gadd wrote:
> On 22/03/16 19:00, The Wanderer wrote:
> >... <see above>
> >
> >How did you test? By launching a new terminal (with bash set as your
> >default shell), by running the command 'bash' in an existing terminal,
> >by logging all of the way out (to the main login prompt, if not to a
> >full reboot) and then logging back in, or by running the command 'bash
> >--login' in an existing terminal?
> >
> >In my testing just now, only the latter two of these four will pick up
> >the new ~/.profile file; the other two seem to run the commands which
> >were present in the file which their parent bash session used. (Strictly
> >speaking I didn't test the full logout or reboot, but I fully expect
> >that that would pick up the changes.)
> >
> >
> >Also, at least on my system, ~/.bashrc is invoked only by being sourced
> >from ~/.profile or ~/.bash_profile. Unless your system is configured
> >fairly differently, if ~/.bashrc is getting run, that means that - per
> >bash(1) - one of ~/.bash_profile, ~/.bash_login, or ~/.profile must be
> >invoking it.
> >
> I tested by rebooting each time. My ~/.bashrc is sourced from
> ~/.profile which itself is sourced from .bash_profile, but neither
> of them run the echo command I've added so I would assume the
> ~/.bashrc which runs when I open a Mate terminal is started some
> other way.

Take a look at   man bash   which will tell you that ~/.bashrc is run
whenever an interactive non-login bash is started. Opening a terminal
session with bash is exactly that.

> bash --login does invoke ~./bash_profile and hence ~./profile as the
> echos are seen in the output file (in the expected order), but I
> must admit the nature of login shells / non-login / interactive
> shells, etc is a bit beyond my experience. I've never tried bash
> --login before as I haven't previously come across it.

Normally, you don't have to run bash --login because it's done for you
by virtue of having /bin/bash in your line of /etc/passwd. However,
that presupposes you're logging in to a VC and then running X with the
startx command. It seems likely that you're not.

> Maybe what this is telling me is that I should run another script
> from my "login" script by 'bash --login real_login_scriptfile' in
> order to get these profiles to run first?

I don't know what you mean by   "login" script   because you haven't
yet told us (I believe) what your machine is configured to do when
you boot it up. If you've installed some sort of Desktop Environment,
then the DE has the responsibility of selecting the shell that runs
your   "login" script   and, indeed, what the filename of that script
is.

If that shell is not bash, then you should put all the environment
commands (basically anything that should only be executed once) in a
file that's *likely* to be called ~/.profile and the rest in
~/.bashrc. But you need to find out what the former should be
called by consulting the DE documentation.

Why .bashrc for a non-bash shell? Assuming you use bash as your
normal shell, you want all your functions and so on available.
However, a non-bash shell (like Debian's default dash shell) will
choke on bash's syntax as well as not being able to execute its
functions.

If you sometimes login with bash (eg remotely), then set your
~/.bash_profile to call both ~/.profile (for the one-off environment
stuff you've just set up) and ~/.bashrc (for the functions).

BTW bear in mind that some operations may be disrupted by having
startup files like .bashrc that aren't mute. It's probably not that
important while you're getting things sorted out, but you might want
to change them to something like this if you intend keeping things noisy:

[ -n "$PS1" ] && printf '%s\n' "(This is $HOME/.bash_profile 2015 July 13)"

Cheers,
David.


Reply to: