Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

.profile not finding new ~/bin directory - SOLVED

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
DocTomJP
Posts: 82
Joined: 2015-06-08 05:21
Location: Thailand
Been thanked: 1 time

.profile not finding new ~/bin directory - SOLVED

#1 Post by DocTomJP »

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.

L_V
Posts: 1477
Joined: 2007-03-19 09:04
Been thanked: 11 times

Re: .profile not finding new ~/bin directory

#2 Post by L_V »

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.

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: .profile not finding new ~/bin directory

#3 Post by Dai_trying »

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.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: .profile not finding new ~/bin directory

#4 Post by Head_on_a_Stick »

~/.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).
deadbang

User avatar
sunrat
Administrator
Administrator
Posts: 6412
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 116 times
Been thanked: 462 times

Re: .profile not finding new ~/bin directory

#5 Post by sunrat »

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!

L_V
Posts: 1477
Joined: 2007-03-19 09:04
Been thanked: 11 times

Re: .profile not finding new ~/bin directory

#6 Post by L_V »

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.

DocTomJP
Posts: 82
Joined: 2015-06-08 05:21
Location: Thailand
Been thanked: 1 time

Re: .profile not finding new ~/bin directory

#7 Post by DocTomJP »

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.

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: .profile not finding new ~/bin directory

#8 Post by Dai_trying »

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.

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 47 times

Re: .profile not finding new ~/bin directory

#9 Post by reinob »

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.

L_V
Posts: 1477
Joined: 2007-03-19 09:04
Been thanked: 11 times

Re: .profile not finding new ~/bin directory

#10 Post by L_V »

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.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: .profile not finding new ~/bin directory

#11 Post by Head_on_a_Stick »

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?
deadbang

User avatar
sunrat
Administrator
Administrator
Posts: 6412
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 116 times
Been thanked: 462 times

Re: .profile not finding new ~/bin directory

#12 Post by sunrat »

@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!

DocTomJP
Posts: 82
Joined: 2015-06-08 05:21
Location: Thailand
Been thanked: 1 time

Re: .profile not finding new ~/bin directory

#13 Post by DocTomJP »

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.

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: .profile not finding new ~/bin directory

#14 Post by Dai_trying »

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.

DocTomJP
Posts: 82
Joined: 2015-06-08 05:21
Location: Thailand
Been thanked: 1 time

Re: .profile not finding new ~/bin directory

#15 Post by DocTomJP »

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.

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: .profile not finding new ~/bin directory

#16 Post by Dai_trying »

When you added the .xsessionrc file you would have to re-boot (or maybe just logout and back in might work) for it to take effect, the difference is that with this being in .bashrc file the $PATH is only set when using a terminal (with bash) and not system-wide, I have used this method for quite some time and it is only since this thread provided me with the (now preferred) alternative of using .xsessionrc the path will always be available.

For instance if you use .bashrc and have a script in your ~/bin/ folder called myscript.sh and try to run it from the application finder (Alt+F2) it will not find your myscript.sh file, whereas if you put the $PATH direction into .xsessionrc it will be available globally and can be run from Application Finder (after a reboot).

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: .profile not finding new ~/bin directory

#17 Post by Head_on_a_Stick »

I've just tested the live version of Cinnamon and it doesn't read ~/.profile, which is strange because my GNOME desktop does. Perhaps this is a bug in the Cinnamon desktop.

I can confirm that ~/.xsessionrc works in Cinnamon, make sure you log out & back in again to see the effect (as Dai notes).
deadbang

DocTomJP
Posts: 82
Joined: 2015-06-08 05:21
Location: Thailand
Been thanked: 1 time

Re: .profile not finding new ~/bin directory

#18 Post by DocTomJP »

Gentlemen : you have steered me to success!

I set the xsessionrc file as you instructed, and now I have the ~/bin file appended.

For information, the difference between the latest and the earlier attempt (that failed) was simply that after deleting the original .bashrc file, and importing the one from skel, the files created thereafter were set to root as owner. This I did not notice on the first attempt with .xsessionrc. But on the latest successful pass at it, I did notice the root ownership, so I changed the owner to me, and all was good after that.

So I am up and running with the ~/bin file in the PATH, as required.

I am extremely grateful for all your help. Not only have you got my issue solved, but you have taught me a few things in the process.

So regards and very many thanks, Tom.

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: .profile not finding new ~/bin directory

#19 Post by Dai_trying »

You're welcome, if you could mark the post as solved (edit title of first post) others could find it easier in the future.

Post Reply