lerner
Posts: 510
Joined: Sun Mar 29, 2015 12:12 am

PATH question - research done.

Sun Oct 22, 2017 7:26 am

Hi folks.

I searched and found this link:
viewtopic.php?t=9033

About PATH.

They were asking about how to "expand" the existing path.
path=$path:/home/pi/productx/bin
Reply:
Add that same line (PATH should be all in uppercase BTW) to the end of ~/.profile
So I did a bit of looking at the ~/.profile file.

Found this part:

Code: Select all

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
Ok, so...... If I enter >echo $PATH< into the terminal, I should see that added - if I make a "bin" directory in my home folder.

Code: Select all

[email protected]:~ $ ls
bin                   Documents  MEDIA           Music            PDF       Public        scratchgpio  Spread sheets  UnPacked_Software
chipdisco_config.txt  Downloads  Mine            names-hosts.txt  Pictures  python_games  sketchbook   TEMP           Videos
Desktop               dwhelper   mount_list.txt  oldconffiles     PiFace    Scratch       Sn00ze       Templates
[email protected]:~ $ 
And now to see if it was added.....

Code: Select all

[email protected]:~ $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
[email protected]:~ $ 
Bit hard to tell. I can't get all that stuff and where the delimiters are.

So I'll try another tack, and with MY directory I use/made:
(Note the Mine directory)

Added this to the .profile file

Code: Select all

PATH="/home/pi/Mine:$PATH"
Now let's see if it is there.....
New terminal session opened.

Code: Select all

[email protected]:~ $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
[email protected]:~ $ 
I can't see it.

This is the ENTIRE .profile file.

I put my extra bit all by itself for now.
I will include the if ---- fi around it later - if/when I get it working.

Code: Select all

# ~/.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 if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
PATH="/home/pi/Mine:$PATH"
Anyone feeling helpful?

I can't learn if examples shown to me don't work.

jahboater
Posts: 5413
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: PATH question - research done.

Sun Oct 22, 2017 7:44 am

See the top of the file for a hint:

# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.

Use "ls -a" to see all the files in your home folder. Files starting with '.' are hidden from normal view (to avoid clutter). The -a option to "ls" shows them all.
~ expands to $HOME by the way which is you home directory.

Put it in ~/.bashrc

In fact there is an alias in ~/.bashrc called "la" which shows all your files.

DirkS
Posts: 10292
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: PATH question - research done.

Sun Oct 22, 2017 8:13 am

AFAIK .profile is only read when logging in, not when starting a new terminal session.
So try logging out and in to see if the path changes are picked up

lerner
Posts: 510
Joined: Sun Mar 29, 2015 12:12 am

Re: PATH question - research done.

Sun Oct 22, 2017 9:15 am

AFAIK .profile is only read when logging in, not when starting a new terminal session.
So try logging out and in to see if the path changes are picked up

You ARE correct.

Ooops to me.

I seem to be burning a lot of pants these days.

I didn't think of logging out and back in.

I thought the M$ Windoze days were behind me.

I shouldn't think too much - it seems.

Ok, it works. Though that in itself is good, it doesn't really help me, as all the files are scripts and their names.... anyway. I've learned something else today.

User avatar
rpdom
Posts: 16715
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: PATH question - research done.

Sun Oct 22, 2017 10:10 am

lerner wrote:
Sun Oct 22, 2017 9:15 am
I didn't think of logging out and back in.
The file in question gets run when you log in, so anything that changes how it works will only be triggered by logging in again.

Return to “Beginners”