Pre-setting paths for terminal

In a previous life, well, on a prev distro, i spent hours reading about .bashrc .profile … etc. Armed with that font of knowledge i packed my CLI toolkit and marched to the front line confident that i knew not only what to do but i knew where the best place to put the call to the paths i would always want.
OK, that’s a while ago, i’m old and my memory sucks, so i can’t remember exactly now what order had been recommended. What i do distinctly remember is that the first choiceS of files recommended by the articles i had read did not exist and that i ended up adding my path, well called my paths subroutine, (sorry, i still think in Fortran 3 terms) to the .bashrc file as a copout.

Is there a “preferred” or “better” way to set the pre-paths each time a terminal is started please?

N.B.
I have a single user machine, if anyone else did want to use it, i would make a new user for them and they would certainly not want/need to use CLI.

Addon Question
Does the EOS rolling update process ever update, i.e. destroy my updates, the .bashrc file … or .profile etc files?

IMHO and experience with dot files, the best place is .profile, which you should confirm it is sourced from .xprofile as well (for GUI/X apps), having a single point for such basic configuration (env vars), that are used from both CLI and GUI processes.

No system package update would touch local/user folders ever. If this is done, it is a bug. Only possible changes (for local SysAdmin) are /etc/xdg and /etc/skel/, and a couple others I would have to search for confirming (since I am also too old to remember everything and always :rofl: ).

Thanks for the reply and sorry for the delay @petsam…IRL

There wasn’t a .profile on my machine at all (yes, i did set hidden files in catfish). There also isn’t an .xprofile
As my $HOME directory didn’t have a .profile file i created one and added my bits ( the line “. /home/mine/bin/udpath.sh” which echo’s the current path then adds to it and echo’s it again)
However, when i started a terminal my paths had not been added.
The line i added did work on my prev distro although i added it to .bashrc in that case (yes, the file it sources to does exist and it is unchanged from my prev distro)

Any thoughts on why this isn’t working please?

There are a few checks to be made.
If I don’t see real data, my only hope is my Crystal Ball :crystal_ball: , but it’s away for summer vacations these days :joy: .
Post:

ls -na $HOME  | grep -v "^d"
ls -n $HOME/bin/udpath.sh # or whatever path is your script

In short, here is one of the many ways it can be done:

# Assuming the local path I use is $HOME/.local/bin
# Add local bin path
if ! $(echo $PATH | grep -oqE "(^|:)$HOME/.local/bin($|:)") ; then
	export PATH="$HOME/.local/bin:$PATH"
fi

Sorry about that @petsam

  • it was late when i posted; two little ones were causing the usual chaos & i’d had a long day.

Also sorry as it seems to be working now (see below)

$ ls -na $HOME  | grep -v "^d"
total 184
-rw-r--r--  1 1000 1000   306 Feb 23 11:00 .bash_aliases
-rw-------  1 1000 1000  2967 Jul 16 18:54 .bash_history
-rw-r--r--  1 1000 1000    21 Jan  8  2022 .bash_logout
-rw-r--r--  1 1000 1000    57 Jul 10 11:19 .bash_profile
-rw-r--r--  1 1000 1000  2691 Jul 16 15:51 .bashrc
-rw-r--r--  1 1000 1000    23 Jul 10 14:19 .dmrc
-rwxr-xr-x  1 1000 1000 18477 Jun  1 12:15 .face
-rw-------  1 1000 1000     0 Jul 10 14:19 .ICEauthority
-rw-------  1 1000 1000    20 Jul 15 18:32 .lesshst
-rw-r--r--  1 1000 1000    86 May 29 17:23 .nanorc
-rw-r--r--  1 1000 1000   375 Jul 16 17:01 .profile
-rw-------  1 1000 1000    50 Jul 17 07:10 .Xauthority
-rwxr-xr-x  1 1000 1000    38 May 29 17:23 .Xresources
-rw-------  1 1000 1000  5202 Jul 17 07:18 .xsession-errors
-rw-------  1 1000 1000 44189 Jul 16 19:01 .xsession-errors.old

$ ls -n /home/mine/bin/udpath.sh
-rwxr-xr-x 1 1000 1000 586 Jan 19 16:33 /home/mine/bin/udpath.sh
type or paste code here

FYI
The .profile file i created contains a source call (shown above) to this:

$ cat /home/mine/bin/udpath.sh
#!/bin/bash
# call:	/home/mine/bin/udpath.sh
echo "e1" $PATH
# printf "p1 $PATH\n"
PATH="${PATH:+${PATH}:}/home/mine/bin"
echo "e2" $PATH
# printf "p2 $PATH\n"
export PATH
PATH="${PATH:+${PATH}:}/home/mine/bin/perl"
echo "e3" $PATH
# printf "p3 $PATH\n"
export PATH
#
# Adding new directory to the PATH variable for all users
# The global path can be updated by either:
# 1. Adding a new file named /etc/profile.d/mypath.sh to be run upon login for all users, containing:
# PATH=$PATH:/new_path
# (Note: This method will affect all users (existing users and future users).
#

Yes, i do tend to over document … and over simplify (i once had to return from an amazing assignment in Hong Kong to fix something in Macclesfield)

p.s.
i do agree that yours is more, shall we say, “succinct” - neater too!

When i open a terminal the path now working, viz:

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/mine/bin:/home/mine/bin/perl

Did it need a reboot to fix it?

No. Only re-login.
In general, some prayers always help, regardless. :wink:

Good job i didn’t stay up to fix it then :slight_smile:
I think i’m probably past praying for…

Thanks again @petsam, you’ve been really helpful

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.