Comments below.  Thanks for such a comprehensive answer.

On Tue, Jan 11, 2022 at 3:13 PM Cameron Simpson <c...@cskk.id.au> wrote:

> On 11Jan2022 14:15, linux guy <linuxguy...@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.

#####################################################################################################



>
> >How does one get the bash environment reloaded without logging out and
> >logging in ?   $source <something> ?  $exec bash ?  ./bash ?
>
> If your terminals run login shells, opening a new terminal will do. For
> that terminal, of course.
>
> Or you can source your .profile (or separate script):
>
>     . ~/.bash_profile
>

Right.  This doesn't seem to be working for me.


>$env should include everything in .bash_profile, right ?
>
> "env" shows the exported environment - that which is inherited by
> subprocesses. Example:
>
>     foo=bah
>     PATH=$HOME/bin:$PATH:/usr/local/bin
>     export PATH
>
> $PATH gets exports, $foo does not, so env will show $PATH and not $foo.
> But your local shell has $foo for whatever purpose.
>

Right.  I get that.

Note that _inherited_ variables are automatically reexported. Because if
> this, good practice is to only export $UPPERCASE names, and to use
> $lowercase names for unexprted variables. This is because only
> discipline controls the use of this namespace. besides, it also makes it
> obvious which variables you expect to be local and which exported.
>

Good tip.


> >Why doesn't F35 have ~/.profile or ~/.bashrc and instead has
> >~/.bash_profile ?  Does .bash_profile replace .bashrc and .profile ?
> Would
> >bash read .profile if I created one ?  If so, when ?
>
> See "man bash". Bash uses .bash_profile for logins and .bashrc for
> nonlogin interactive shells.
>

OK, this makes sense.

>What happened to .inputrc ?
>
> The .inputrc is for controlling the readline library (used for
> interaction in bash and various other things). Maybe the defaults are
> considered nice enough - you can always add your own. Here's mine:
>
>     set editing-mode emacs
>     set blink-matching-paren on
>     set completion-ignore-case on
>     set completion-query-items 1024
>     set disable-completion off
>     set expand-tilde on
>     set horizontal-scroll-mode off
>     set mark-directories on
>     set mark-symlinked-directories on
>     set match-hidden-files off
>     set page-completions on
>     set print-completions-horizontally off
>     set show-all-if-ambiguous on
>     set visible-stats on
>     Control-w:backward-kill-word
>

Thanks for the detailed answer.
_______________________________________________
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org
Do not reply to spam on the list, report it: 
https://pagure.io/fedora-infrastructure

Reply via email to