.profile not finding new ~/bin directory - SOLVED

Kernels & Hardware, configuring network, installing services

.profile not finding new ~/bin directory - SOLVED

Postby DocTomJP » 2019-12-01 13:14

I understand from various sources on the net that user scripts are best placed in a ~/bin directory. I have made such a directory.

Various sources also state that on creation (after logout and logon) the new directory should be added to the PATH variable. Indeed the .profile file seems to confirm this, if I understand it correctly, with the code

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

But in my case the PATH variable is unaltered after creating the new ~/bin directory. (There are no other relevant files in my home directory other than.bashrc which does not have a PATH statement in it.)

I guess that I am making some stupid mistake or misunderstanding. Nevertheless I will be very grateful if someone can explain to me what is (not) going on, and advise me how to proceed.

Tom.
Last edited by DocTomJP on 2019-12-11 14:26, edited 1 time in total.
DocTomJP
 
Posts: 23
Joined: 2015-06-08 05:21

Re: .profile not finding new ~/bin directory

Postby L_V » 2019-12-01 13:31

Just to check:
Code: Select all
$ echo $PATH
$ echo $SHELL
$ ls -l ~/bin ~/.profile
Last edited by L_V on 2019-12-01 13:45, edited 2 times in total.
L_V
 
Posts: 1171
Joined: 2007-03-19 09:04

Re: .profile not finding new ~/bin directory

Postby Dai_trying » 2019-12-01 13:34

I have noticed this before and I simply paste that code into ~/.bashrc to make it available in my terminal, although if you want the path available system wide then you would need a different approach.
Dai_trying
 
Posts: 836
Joined: 2016-01-07 12:25

Re: .profile not finding new ~/bin directory

Postby Head_on_a_Stick » 2019-12-01 16:59

~/.profile isn't read for graphical logins.

See https://wiki.debian.org/EnvironmentVariables

tl;dr: add the PATH stuff to ~/.xsessionrc instead (or use a console login rather than a display manager).
Don't break DebianHow to report bugs

SharpBang GNU/Linux® — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10695
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: .profile not finding new ~/bin directory

Postby sunrat » 2019-12-01 21:12

Head_on_a_Stick wrote:~/.profile isn't read for graphical logins.

See https://wiki.debian.org/EnvironmentVariables

tl;dr: add the PATH stuff to ~/.xsessionrc instead (or use a console login rather than a display manager).


Weird, it works for me in a fairly vanilla Buster/KDE which uses SDDM. I know it says it doesn't on that wiki page. There is no ~/.xsessionrc but the ~/bin PATH is set by default in ./.profile (ie. I didn't add it)

Code: Select all
roger@debian-brain:~$ echo $PATH
/home/roger/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!
User avatar
sunrat
 
Posts: 2920
Joined: 2006-08-29 09:12
Location: Melbourne, Australia

Re: .profile not finding new ~/bin directory

Postby L_V » 2019-12-01 21:19

If I also ask DocTomJP to report $SHELL, is because in case zsh is used as default shell instead of bash, ~/.profile is not used, but ~/.zprofile.
BTW, never had any problem with ~/bin path setting.
L_V
 
Posts: 1171
Joined: 2007-03-19 09:04

Re: .profile not finding new ~/bin directory

Postby DocTomJP » 2019-12-02 00:36

Gentlemen : many thanks indeed for all your inputs.
In responding to L_V I get some output that I do not understand...

drtjpike@AspireV5:~\ $ >> echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
drtjpike@AspireV5:~\ $ >> echo $SHELL
/bin/bash
drtjpike@AspireV5:~\ $ >> ls -l ~/.profile
-rw-r--r-- 1 drtjpike drtjpike 675 May 29 2018 /home/drtjpike/.profile
drtjpike@AspireV5:~\ $ >> ls -l ~/bin
total 0
drtjpike@AspireV5:~\ $ >> ls -l
total 88
-rw-r--r-- 1 drtjpike drtjpike 0 Nov 29 10:04 '[033[00m]'
drwxr-xr-x 2 drtjpike drtjpike 4096 Nov 27 17:42 bin
-rw-r--r-- 1 drtjpike drtjpike 51446 Jul 23 12:54 curr-pkgs.txt
drwxr-xr-x 2 drtjpike drtjpike 4096 Jul 26 07:57 Desktop
drwxr-xr-x 3 drtjpike drtjpike 4096 Aug 1 11:00 Documents
drwxr-xr-x 2 drtjpike drtjpike 4096 Jul 18 08:14 Downloads
drwxr-xr-x 2 drtjpike drtjpike 4096 May 29 2018 Music
drwxr-xr-x 2 drtjpike drtjpike 4096 Jul 18 08:15 Pictures
drwxr-xr-x 2 drtjpike drtjpike 4096 May 29 2018 Public
drwxr-xr-x 2 drtjpike drtjpike 4096 Jul 23 12:30 Templates
drwxr-xr-x 2 drtjpike drtjpike 4096 May 29 2018 Videos

When I do ls -l~/bin I get a response total 0, but when I do ls -l the bin directory shows up in the list!

Please note that I am doing all these actions from the bash session at the terminal, not using the GUI.\

I looked at the /etc/profile file, and it appears that the PATH variable is set from there .....

if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH

The PATH after the else statement is what I have as my path as you see from my echo $PATH command.

I remain confused as to what is going on, and the best way to proceed.

(Note - I forgot to mention that I am running Debian Buster with Cinnamon as the desktop.)

Thanks again for your contributions, Tom.
DocTomJP
 
Posts: 23
Joined: 2015-06-08 05:21

Re: .profile not finding new ~/bin directory

Postby Dai_trying » 2019-12-02 07:33

Head_on_a_Stick wrote:add the PATH stuff to ~/.xsessionrc instead.


This is the best way to add your ~/bin folder in the path system-wide. You may need to create ~/xsessionrc first but if you use nano it will be automatically created if it does not exist.
Dai_trying
 
Posts: 836
Joined: 2016-01-07 12:25

Re: .profile not finding new ~/bin directory

Postby reinob » 2019-12-02 08:47

I'll just add that normally when you run a terminal emulator (I use lxterminal) it will *not* run a login shell, which means (in the case of bash) that .bashrc will be read (because it's an interactive shell), but not .profile (or .bash_profile if it exists).

You can easily check with "echo $0", if it says "bash" then it's an interactive non-login shell.
If it says "-bash" then it's a logins shell.

I run lxterminal with "lxterminal --loginshell" which takes care of running bash with "--login", so that .profile will be read.
reinob
 
Posts: 755
Joined: 2014-06-30 11:42

Re: .profile not finding new ~/bin directory

Postby L_V » 2019-12-02 09:35

DocTomJP wrote:drtjpike@AspireV5:~\ $ >> ls -l ~/bin
total 0

Nothing wrong here. The directory ~/bin exists, but is empty.

However, your prompt is not the default one, and you have some a strange file called '[033[00m]'
I suppose you don't test with a default .bashrc file.

Could you try to replace your current ~/.bashrc with this one: /etc/skel/.bashrc , and test again.
L_V
 
Posts: 1171
Joined: 2007-03-19 09:04

Re: .profile not finding new ~/bin directory

Postby Head_on_a_Stick » 2019-12-02 18:04

sunrat wrote:Weird, it works for me in a fairly vanilla Buster/KDE which uses SDDM. I know it says it doesn't on that wiki page. There is no ~/.xsessionrc but the ~/bin PATH is set by default in ./.profile (ie. I didn't add it)

Yes, this is a very good point. I also have some custom variables exported from ~/.profile and they are applied in GNOME, not sure why this didn't register for me earlier... :?

@OP: what is the content of ~/.profile? Have you changed it at all?
Don't break DebianHow to report bugs

SharpBang GNU/Linux® — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10695
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: .profile not finding new ~/bin directory

Postby sunrat » 2019-12-02 21:44

@DocTomJP indeed there is something weird going on in your system. L_V and I both have it working by default. A default bash prompt does not have >> between the $ and the command. I have no idea why it is showing this but you need to find out. Try replacing your ~/.bashrc as L_V suggested in his last post. Back up the old one first of course.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!
User avatar
sunrat
 
Posts: 2920
Joined: 2006-08-29 09:12
Location: Melbourne, Australia

Re: .profile not finding new ~/bin directory

Postby DocTomJP » 2019-12-03 02:31

Gentlemen : I am part way in going through your recommendations. Here is a progress report.

1. My prompt is a result of my fiddling around to get a more easily visible one. I only edited the code relating to the prompt in .bashrc, nothing else.

2. The strange file 033 or whatever was a left-over from the actions in 1) above. It was a LibreOffice text, with nothing left in it. I deleted it.

3. I replaced the .bashrc file with the one from /etc/skel and the $PATH remained unchanged ....

Code: Select all
drtjpike@AspireV5:~\ $ >> echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
drtjpike@AspireV5:~\ $ >> echo $SHELL
/bin/bash

4. The .profile file is copied below...

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


I am guessing that for some reason the last few lines of code are not being executed - or perhaps the whole .profile file is not being read.

5. There is no file regarding the xsession that was mentioned (I forget its name as I type this), only xsession.errors and .errors.old.

6. So it looks as though the next thing to try is to create that xsession file and add some code. Is that the best next step?

Again many thanks for your help and forbearance. Tom.
DocTomJP
 
Posts: 23
Joined: 2015-06-08 05:21

Re: .profile not finding new ~/bin directory

Postby Dai_trying » 2019-12-03 08:04

DocTomJP wrote:6. So it looks as though the next thing to try is to create that xsession file and add some code. Is that the best next step?


Dai_trying wrote:
Head_on_a_Stick wrote:add the PATH stuff to ~/.xsessionrc instead.


This is the best way to add your ~/bin folder in the path system-wide. You may need to create ~/xsessionrc first but if you use nano it will be automatically created if it does not exist.
Dai_trying
 
Posts: 836
Joined: 2016-01-07 12:25

Re: .profile not finding new ~/bin directory

Postby DocTomJP » 2019-12-07 06:45

Gentlemen : sorry for the delay in response - grandson demanding attention!

I started this query with an almost non-existent and in parts erroneous knowledge of the login process and its relation to the issue. After your help and some searches on the web I am beginning to get a glimmer of understanding, I think.

So I now understand that when I input my password etc at startup I am actually in a non-login shell, I suppose controlled by Cinnamon.

Thus I tried the other views (I forget the technical term) by hitting Cntrl-Alt-F3, as I believed it to be a login shell, and sure enough the PATH shows the ~/bin directory.

Reverting to the Cinnamon view, I did try to set the .xsessionrc file to read the PATH statement that I require. The file was created. I placed the statement export PATH=$PATH:~/bin therein. and tried the echo $PATH command.

No luck, even after closing and re-opening the terminal, and a shutdown and re-boot. The ~/bin file was absent.

So I tried putting the same statement at the end of the .bashrc file, and this worked ...

[/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/drtjpike/bin] .

So I have the PATH that I wanted. But is the edit of the .bashrc file a suitable solution, or will there be problems ahead?

I an grateful indeed for all your help. You experts on this forum are very generous with your time and forbearance of amateurs like me.

Tom.
DocTomJP
 
Posts: 23
Joined: 2015-06-08 05:21

Next

Return to System configuration

Who is online

Users browsing this forum: No registered users and 15 guests

fashionable