1

I'm using in xubuntu bionic as shell bash.

I'll try to expand my $PATH for my user over $HOME/.profile.

if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

The result is a little bit unexpected.

echo $PATH
/home/alex/.local/bin:/home/alex/bin:/home/alex/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

$HOME/bin is set twice. How can I avoid it?

In $HOME/.bashrc is nothing declared.

  • 1
    The lines you show should exist by default in $HOME/.profile since the are copied from /etc/skel/.profile when you created the user – mook765 Aug 29 '19 at 20:42
1

I use Stephen Collyer's "Bash Path Functions" (see his article Stephen Collyer's article in Linux Journal). It permits me to use the "colon separated list" as a datatype in shell programming. For example, I can produce a list of all the directories in the current directory by:

dirs="";for i in * ; do if [ -d $i ] ; then addpath -p dirs $i; fi; done  

Then, listpath -p dirs produces a list.

Using uniqpath and listpath (from bash_path_funcs), one could simply:

walt@bat:~(0)$ PATH=$HOME/bin:$PATH
+walt@bat:~(0)$ listpath
/home/walt/bin
/home/walt/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin
/home/walt/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

+walt@bat:~(0)$ uniqpath -p PATH
+walt@bat:~(0)$ listpath
/home/walt/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/gameswalt@bat:~(0)$ PATH=$HOME/bin:$PATH
  • this looks interesting. – nobody Aug 29 '19 at 16:00
2

Ubuntu is already configured to automatically add $HOME/bin to the path.

You mentioned you're distribution was Server converted to Desktop and I'm not sure how that effects things but you can check:

$ 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

# 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 directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"

It sounds like this is being executed and what you are manually doing is doubling up on the last line in the file.


Using grep to find all references

You can use grep to find all the files where $HOME/bin is referenced:

grep -rnw --exclude-dir={proc,root,run,sys,/tmp,tmpfs,var} '/' -e "$HOME/bin"
  • No, it was not. – nobody Aug 29 '19 at 15:55
  • I'm at work but when I get home I'll find the exact place it is set and update the answer. Which version of Ubuntu are you using? – WinEunuuchs2Unix Aug 29 '19 at 17:09
  • unmodified user echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games as I wrote xubuntu bionic. with cfce4-session. It was a server installation first ;D – nobody Aug 29 '19 at 17:31
  • 1
    The current .profile checks for the existence of a bin or .local/bin before adding it to the PATH. @nobody an unmodified user will not have a bin directory, so in that case, not adding the bin to the PATH is correct. – ubfan1 Aug 30 '19 at 3:44
  • 1
    @ubfan1 When I checked /etc/skel/.profile it is identical. I'm on Ubuntu 16.04.6 LTS though. – WinEunuuchs2Unix Aug 30 '19 at 4:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.