personal bin directory fix

Here is where you can post tips and tricks to share with other users of MX. Do not ask for help in this Forum.
Message
Author
seasoned_geek
Posts: 23
Joined: Wed Jul 30, 2025 11:53 am

personal bin directory fix

#1 Post by seasoned_geek »

You need to add

Code: Select all

echo ".bashrc executed"
if [ -d "$HOME/bin" ]; then
   export PATH="$HOME/bin":$PATH
   echo "added to PATH"
fi
with or without the echo statements to the top of .bashrc if you want your personal bin directory to be in your path. This code in .profile

Code: Select all

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists

echo ".profile executed"
if [ -d "$HOME/bin" ]; then
   export PATH="$HOME/bin":$PATH
   echo "added to PATH"
fi


# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi 
is never executed. I added the echo statements in .profile trying to debug this.

BV206
Posts: 555
Joined: Sat Mar 09, 2019 10:55 am

Re: personal bin directory fix

#2 Post by BV206 »

I don't know if this is still true but Debian and some other distros used to require a file called ~/.xsessionrc to be present or else ~/bin or ~/.local/bin won't work in your path.
I always just copy it but not sure if it is still needed. You could try making one and see if that fixes it. I'm sure you need to log out or reboot for it to take effect.

~/.xsessionrc contains:

Code: Select all

if [ -f ~/.profile ]; then
    . ~/.profile
fi

BV206
Posts: 555
Joined: Sat Mar 09, 2019 10:55 am

Re: personal bin directory fix

#3 Post by BV206 »

Also ~/.profile needs the following for the bin folders to work:

Code: Select all

# if running bash
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi
I think that is from the default file. I don't remember modifying the path statements.

User avatar
Michael-IDA
Posts: 371
Joined: Sat Jan 12, 2019 8:00 pm

Re: personal bin directory fix

#4 Post by Michael-IDA »

seasoned_geek wrote: Tue Aug 05, 2025 2:50 pm You need to add

to the top of .bashrc
It's usually better to add it to the end of the file so it doesn't disrupt expected behaviors and your changes don't get overwritten. Or add something like this:

Code: Select all

if [ -f /home/michael/bin/.bashrc ]; then
  . /home/michael/bin/.bashrc
fi
to the end of .bashrc for better portability and convenience.

* You can use "$HOME/bin/.bashrc" instead, but then you have to watch out for $HOME not being set (granted that happens very rarely).
NIH Cancer Study: The group supplemented with both vitamins and fenbendazole exhibited significant (P = 0.009) inhibition of tumor growth.
The day Microsoft makes a product that doesn't suck...
... is the day they make a vacuum cleaner.

seasoned_geek
Posts: 23
Joined: Wed Jul 30, 2025 11:53 am

Re: personal bin directory fix

#5 Post by seasoned_geek »

Michael-IDA wrote: Tue Aug 05, 2025 3:15 pm
It's usually better to add it to the end of the file so it doesn't disrupt expected behaviors and your changes don't get overwritten. Or add something like this:

Code: Select all

if [ -f /home/michael/bin/.bashrc ]; then
  . /home/michael/bin/.bashrc
fi
to the end of .bashrc for better portability and convenience.

* You can use "$HOME/bin/.bashrc" instead, but then you have to watch out for $HOME not being set (granted that happens very rarely).
Adding to the end puts anyone running batch/detached/non-interactive jobs in a world of hurt though.


Image

If they didn't bail at the top when not interactive, I would agree.

User avatar
Michael-IDA
Posts: 371
Joined: Sat Jan 12, 2019 8:00 pm

Re: personal bin directory fix

#6 Post by Michael-IDA »

seasoned_geek wrote: Tue Aug 05, 2025 3:19 pm Adding to the end puts anyone running batch/detached/non-interactive jobs in a world of hurt though.
Image

If they didn't bail at the top when not interactive, I would agree.
Hmmm, you missed the first line?

Code: Select all

# ~/.bashrc: executed by bash(1) for non-login shells.
"The file is just shell commands. It is typically used to change prompts, set environment variables, and define shell procedures." *

I'd say nothing a non-interactive type job needs, but...

My opinion, "batch/detached/non-interactive jobs" almost always have to be written such that they assume no 'help' from anywhere. You generally don't code 'tar' you code '/usr/bin/tar'. I mean you can, but it kinda screws with being portable.

And mostly that's solved by having a shared file with all your normal setups sourced in at the top of each non-interactive job. Again my opinion, but it sure makes debugging a whole lot easier...

Best,
Michael

* Swiped from: https://superuser.com/questions/49289/w ... ashrc-file
NIH Cancer Study: The group supplemented with both vitamins and fenbendazole exhibited significant (P = 0.009) inhibition of tumor growth.
The day Microsoft makes a product that doesn't suck...
... is the day they make a vacuum cleaner.

seasoned_geek
Posts: 23
Joined: Wed Jul 30, 2025 11:53 am

Re: personal bin directory fix

#7 Post by seasoned_geek »

Michael-IDA wrote: Tue Aug 05, 2025 3:53 pm
Hmmm, you missed the first line?

Code: Select all

# ~/.bashrc: executed by bash(1) for non-login shells.
"The file is just shell commands. It is typically used to change prompts, set environment variables, and define shell procedures." *

I'd say nothing a non-interactive type job needs, but...
The first line is incorrect. I learned long ago to never trust comments in old code, especially in a Linux environment. :number1:

I added the echo statements to prove the comment was wrong.


Image

That would be what I see when I open an interactive terminal.

Someone broke Linux culture and opted to not use .profile. Most likely, same someone didn't update the comments.

The default debugger, it's a wonderful thing! 8)

User avatar
RedGreen925
Posts: 39
Joined: Sat Feb 01, 2025 3:21 pm

Re: personal bin directory fix

#8 Post by RedGreen925 »

I use the following to do it.

In the profile.

Code: Select all

zeus@9600k:~$ cat .profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# include the .bashrc no matter what
if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
fi

# enable it on login if xbindkeys is installed.
if [ -f "/usr/bin/xbindkeys" ]; then
        xbindkeys
fi

mesg n 2> /dev/null || true
Then in the .bashrc I use the following snippets.

Code: Select all

zeus@9600k:~$ cat .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac



#######################################################
# SOURCED ALIAS'S AND SCRIPTS
#######################################################
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

# Use  ~/.bash_functions if it exists

if [ -f ~/.bash_functions ]; then
    . ~/.bash_functions
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/Bin" ] ; then
    PATH="$HOME/Bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi


It includes many variants of a home naming I found and have included ever since. It also sources my aliases and function files. All that needs to be done to have the changes used in the current shell is use source ~/.bashrc and it will be re-read and used.

Post Reply

Return to “Tips & Tricks by users (not for help)”