Comments below. Thanks for such a comprehensive answer.
On Tue, Jan 11, 2022 at 3:13 PM Cameron Simpson <
cs@cskk.id.au> wrote:
On 11Jan2022 14:15, linux guy <linuxguy123@gmail.com> wrote:
>I'm trying to add a few directories to PATH in F35. I'm embarrassed to
>admit it isn't going well.
>
>Where is PATH stored in F35 ?
In your processes' memory. Unhelpful. But it is _initialised_ by your
login sequence. Yes, being pedantic here.
Ha.
>When exactly does .bash_profile get executed ?
1: Is your shell bash? (My interactive shell is zsh, by contrast.)
Echoing $SHELL should confirm bash for you, or looking in /etc/passwd.
Yes, bash.
2: .bash_profile (or .profile, if the former is missing) gets run by
_login_ shells.
Good to know.
On a text based terminal (eg the Linux console without a GUI), your
login runs a login shell.
In a GUI such as a desktop the situation is more complicated:
- the GUI startup does not automatically run a login shell (to some
extend because interaction or mistakes can then easily break the GUI
startup).
Interesting.
- when you start a terminal it may or may not run a login shell; this
can be controlled with the settings for your terminal emulator. What
are you using?
Konsole. According to its settings, it runs /bin/bash when it starts up.
Shells usually have a login and nonlogin startup mode - for bash this
loosely means a login shell sources the .bash_profile (or.profile) on
startup, and nonlogin interactive shells source the .bashrc.
OK, so there is my issue. ~/ does not have a .bashrc. I has .bash_profile only.
The specifics vary for other shells (eg zsh) but the idea's the same. The
exact process for bash is explained in tedious details in "man bash".
RTFM ! RTFMP ! OK.
The basic idea is/was that you'd put expensive stuff which only needed
to happen once in the .bash_profile (setting $PATH, consulting some
summary information, etc) and interactive-useful stuff in your .bashrc
(setting interaction modes like command line editing, defining aliases,
etc).
Makes sense.
These days you can often get away with making every new terminal run a
login shell. Look into that setting first up - it is the easiest fix.
Doesn't appear to be editable in Konsole, though maybe I could specify it as a parameter to /bin/bash that gets executed at startup. Haven't tried that yet.
I discourage you from polluting your .bashrc with complexity. Though a
lot of distros prepollute it for you (have a look at /etc/bashrc, often
a nightmare of complexity).
Mine is pretty clean.
Personally, I keep my environment setting stuff in a distinct script,
which I source from my .profile. Here's my .profile:
#!/bin/sh
umask 002
[ -f $HOME/rc-local/profile ] && . $HOME/rc-local/profile
: ${SHDIR:=$HOME/rc/shell}
. $SHDIR/rigenv
LUSER=$USER; export LUSER
. $HOME/rc/shell/rc
Setting $PATH (and a billion other things) is done in the "rigenv"
script mentioned above.
OK.
Here is my .bashrc:
#########################################################################
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
if [ -d ~/.bashrc.d ]; then
for rc in ~/.bashrc.d/*; do
if [ -f "$rc" ]; then
. "$rc"
fi
done
fi
unset rc
#####################################################################################################
Here is my .bash_profile:
####################################################################################
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
# empty right now.
#####################################################################################################