Debian default $PATH where it comes from?

Kernels & Hardware, configuring network, installing services

Debian default $PATH where it comes from?

Postby pedegie » 2018-10-06 20:36

Hello I'm curious where the default $PATH variable comes from which contains /games/ among others. I was trying to remove it but unsuccessfully. I found that PATH is set in:
/etc/login.defs
/etc/profile
/etc/environment
some .bashrc, .bash_profile, .config files

I removed entry from each file, then reset PC but it still shows `/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games` on echo $PATH.
I know I can just override it but I'm really curious where it comes from.

EDIT: I'm using 4.9.0-8-amd64 #1 SMP Debian 4.9.110-3+deb9u5 (2018-09-30) x86_64 GNU/Linux
pedegie
 
Posts: 4
Joined: 2018-10-06 20:29

Re: Debian default $PATH where it comes from?

Postby Head_on_a_Stick » 2018-10-06 21:23

PATH is set in ~/.profile

~/.profile is copied from /etc/skel/.profile (provided by the bash package) by the adduser(8) program when a new user is created.

EDIT: note though that bash will not read ~/.profile if ~/.bash_profile exists.
"The trouble with the world is that the stupid are cocksure and the intelligent full of doubt." — Bertrand Russell
User avatar
Head_on_a_Stick
 
Posts: 8838
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Debian default $PATH where it comes from?

Postby pedegie » 2018-10-06 21:30

.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
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:/bin"
fi


Yep but I removed also from there

I found
Code: Select all
dbus-update-activation-environment: setting PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

in .xsession-errors. Maybe its related in some way?
pedegie
 
Posts: 4
Joined: 2018-10-06 20:29

Re: Debian default $PATH where it comes from?

Postby Head_on_a_Stick » 2018-10-07 05:32

Debian seems to be setting PATH originally via the sysprofile package and a convoluted series of abstractions which I can't follow atm :?

Luckily for us this all irrelevant because if you have a specific PATH that you wish to set for any given user then simply override the default in ~/.profile, like this:
Code: Select all
export PATH="${HOME}/bin:/usr/local/bin:/usr/bin:/bin"

^ So that would remove /usr{,/local}/games from that user's PATH and add ~/bin ;)

EDIT: your modification of ~/.profile did not work because in that stanza PATH is only set if ~/bin exists and I presume that it does not exist for your user.

My line would set PATH even if ~/bin does not exist (although it would be silly to add ${HOME}/bin to PATH in that case, obviously).
"The trouble with the world is that the stupid are cocksure and the intelligent full of doubt." — Bertrand Russell
User avatar
Head_on_a_Stick
 
Posts: 8838
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Debian default $PATH where it comes from?

Postby pedegie » 2018-10-07 06:16

Alright I put export PATH to .profile, thanks for clarifying and your help :)
pedegie
 
Posts: 4
Joined: 2018-10-06 20:29

Re: Debian default $PATH where it comes from?

Postby Head_on_a_Stick » 2018-10-07 08:23

You're welcome :)

Please add [SOLVED] to the thread title to help others with this problem — it may also be best to change the title to "Debian: setting PATH for user" because I didn't actually find out how the default PATH is set.
"The trouble with the world is that the stupid are cocksure and the intelligent full of doubt." — Bertrand Russell
User avatar
Head_on_a_Stick
 
Posts: 8838
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Debian default $PATH where it comes from?

Postby debiman » 2018-10-07 08:41

pedegie wrote:.profile
Code: Select all
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:/bin"
fi

this is wrong.
where did you get that from?
it should be something like PATH="$HOME/bin:$PATH"

also look at /etc/profile.
User avatar
debiman
 
Posts: 3064
Joined: 2013-03-12 07:18

Re: Debian default $PATH where it comes from?

Postby Head_on_a_Stick » 2018-10-07 09:51

debiman wrote:
pedegie wrote:.profile
Code: Select all
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:/bin"
fi

this is wrong.
where did you get that from?

That was the OP's attempted modification to that file.

It had no effect because ~/bin does not exist for that user ;)
"The trouble with the world is that the stupid are cocksure and the intelligent full of doubt." — Bertrand Russell
User avatar
Head_on_a_Stick
 
Posts: 8838
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Debian default $PATH where it comes from?

Postby Head_on_a_Stick » 2018-10-07 09:54

debiman wrote:look at /etc/profile.

Did you even bother to look in /etc/profile yourself before posting?

I ask because I did check and there is no mention of PATH in that file at all...
"The trouble with the world is that the stupid are cocksure and the intelligent full of doubt." — Bertrand Russell
User avatar
Head_on_a_Stick
 
Posts: 8838
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Debian default $PATH where it comes from?

Postby pedegie » 2018-10-07 13:00

Yep I have this there (which i also modified before posting):

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


Head_on_a_stick: How can I change topic's name? I want add that it's solved
pedegie
 
Posts: 4
Joined: 2018-10-06 20:29

Re: Debian default $PATH where it comes from?

Postby Head_on_a_Stick » 2018-10-07 13:08

pedegie wrote:How can I change topic's name? I want add that it's solved

Edit the first post in this thread, that contains the "title" section for the thread and this is where you need to add [SOLVED].
"The trouble with the world is that the stupid are cocksure and the intelligent full of doubt." — Bertrand Russell
User avatar
Head_on_a_Stick
 
Posts: 8838
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Debian default $PATH where it comes from?

Postby debiman » 2018-10-09 17:39

Head_on_a_Stick wrote:
debiman wrote:look at /etc/profile.

Did you even bother to look in /etc/profile yourself before posting?

I ask because I did check and there is no mention of PATH in that file at all...

i did, and there is.
on my debian system, it is the literal answer to the OP's title.
User avatar
debiman
 
Posts: 3064
Joined: 2013-03-12 07:18

Re: Debian default $PATH where it comes from?

Postby Head_on_a_Stick » 2018-10-09 17:59

^ Really? :o

In which case, sorry about that, my mistake.
"The trouble with the world is that the stupid are cocksure and the intelligent full of doubt." — Bertrand Russell
User avatar
Head_on_a_Stick
 
Posts: 8838
Joined: 2014-06-01 17:46
Location: /dev/chair


Return to System configuration

Who is online

Users browsing this forum: GRzenabI and 6 guests

fashionable