[Solved]Problem modifying $PATH

Forum rules
Before you post please read how to get help
Post Reply
User avatar
DetroitGeek
Level 1
Level 1
Posts: 5
Joined: Sat Nov 13, 2010 8:34 am
Location: Metro Detroit Area

[Solved]Problem modifying $PATH

Post by DetroitGeek » Thu Feb 04, 2016 6:59 pm

My path:
jhoward@NPS-039vx01:~ > echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

Append to /etc/bash.bashrc:
PATH=$PATH:/home/jhoward/scripts

Results in:
jhoward@NPS-039vx01:~ > echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/jhoward/scripts:/home/jhoward/scripts

How did that result in a double entry pointing to /home/jhoward/scripts ?
Last edited by DetroitGeek on Sun Feb 07, 2016 8:13 pm, edited 1 time in total.
If it was easy, anyone could do it.

User avatar
LinuxJim
Level 5
Level 5
Posts: 659
Joined: Tue Jan 26, 2016 8:01 pm
Location: Oregon, USA

Re: Problem modifying $PATH

Post by LinuxJim » Thu Feb 04, 2016 8:45 pm

DetroitGeek wrote: How did that result in a double entry pointing to /home/jhoward/scripts ?
Because, for interactive shells, bash first reads /etc/profile, then /etc/bash.bashrc.

But /etc/profile calls /etc/bash.bashrc, so /etc/bash.bashrc ends up being sourced twice.

The proper place to put things like $PATH entries which are not related to bash would be /etc/profile for system-wide access, or ~/.profile for individual users.

/etc/bash.bashrc and ~/.bashrc are for bash-specific stuff, like setting up the prompt, history size, etc.

Note that this is all simply convention. It's kind of a convoluted mess really, to make bash do different things depending on local/remote, interactive/non-interactive use.
Last edited by LinuxJim on Thu Feb 04, 2016 9:15 pm, edited 1 time in total.

User avatar
Flemur
Level 16
Level 16
Posts: 6990
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Problem modifying $PATH

Post by Flemur » Thu Feb 04, 2016 8:46 pm

Because, for interactive shells, bash first reads /etc/profile, then /etc/bash.bashrc.
He didn't say, but I assumed he was doing with a terminal command.
Edit: Oops, he did say. 'Bye!
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
Mint 19.1 Xfce/fluxbox
Manjaro openbox/fluxbox

atomic.kidd
Level 1
Level 1
Posts: 5
Joined: Thu Feb 04, 2016 10:43 pm

Re: Problem modifying $PATH

Post by atomic.kidd » Thu Feb 04, 2016 11:10 pm

guys sorry to say your going about this the wrong way. If you happen to Edit modify the /etc/bash.bashrc file your going to mess and change the whole system function. (for every user to whom may login to this system don't mess with /etc/ files at all )

the reason your getting double the path statement when you echo $PATH is that - the system checks your logged in - yes - but it really operates thru your user profile settings and more so the User Environment settings -
when you get a new account the system - pulls info and creates your user account via much into the /etc/skel files - which then copies the system default files over to your newly created system account folder.
User Profile - is for to which you have your own environment files there.
Beauties about Linux - is that it is so very close to Unix - if not really the same. the default found to become over time was to create users in Linux with BASH environment. So you have a :

ls .bash*
-rw------- 1 userX userX 54 Dec 28 03:12 .bash_history
-rw-r--r-- 1 userX userX 765 Dec 28 03:20 .bash_profile
-rw-r--r-- 1 userX userX 368 Dec 28 03:20 .bash_logout
-rw-r--r-- 1 userX userX 1740 Dec 28 03:24 .bashrc
and .profile

What happens is when you login your system checks this /etc/bash.bashrc file - which is really used for hotkey settings only - allowing some funky stuff. try typing " alias " in a command prompt and you can see only a few hotkey functions set simple.
basically examples. hotkeys or alias quick command key codes.
once you make changes you have to resource the . .bashrc and the new hotkeys will be available without having to close and reopen the terminal shell. (note the double dots . .bashrc )

.bash_profile is where you edit and add your $PATH changes to match your needs.
same here you may also . .bash_profile to see the immediate change to your PATH statement and it will be singular per user account and environment setting. The only caveat here is - yes this is a deeper action file - so really you can quickly source in the new changes - but really requires a logoff and re-login again. test it out - I'm only providing some tips and hints yeAll.

someone said the .bashrc file is also for prompt - no really that is done on the .bash_profile for its 1st read to prompt when you drop to a terminal cmdline session.

maybe check - bash environment properties and correct use of

or linux environment settings .. there is a ton of stuff .. and even if you have an issue similar - simply google it.. the way you may think it out - see the examples and or play with the examples to verify all - there is a ton of stuff here that can cook your noodle.
its all fun and absorbing.. yes really LOVE LINUX . most all *NIX flavours operate in such manor ..
cheers.

atomic.kidd
Level 1
Level 1
Posts: 5
Joined: Thu Feb 04, 2016 10:43 pm

Re: Problem modifying $PATH

Post by atomic.kidd » Fri Feb 05, 2016 5:50 pm

thought to add - the /etc/bash.bashrc file is for the root user, again - root user will also have his own collection of Environment files as listed - in its own private directory - the .bashrc file is the personal file in your own ~/HOME/USER directory where you can add some very funky stuff to make life easy. Also please do note that all the files I listed are "Hidden" meaning and showing with the period Dot infront of the actual file name. If someone else besides yourself is on your system - if you have more than one user - a work environment enterprize etc. the SysAdmin will protect those files and make sure that no one but Root can access and or have ability to edit. Hence the use of Sudo is quite sensitive to your systems operation. When you shell or open a terminal the .bashrc is read everytime - and loads into memory region your alias hot keys -
example:
cd at any prompt should take you home to your ~/home/username directory
cat .bashrc

This is your hotkey and funky file to personally customize.
.bash_profile is where your prompt and path statements would expand your use on your own system
.bash_logout captures your session info copies your session login and info'z - (which out of box is not that much but sessions like ssh secure connections get logged)
.bash_history is your terminal command line historical index of commands you have entered at the terminal session and can be accessed similar to .bashrc - but at command level and numerically stepped command use.
you can recall history by typing history then simply in shown list type !# or !14 if by chance you have a lengthy list - command entered at index 14 would be repeated. check it out. Sorry thunk I'm getting tutorial here and there is bunches of so very cool schtuff you all can resource on this wonderful world of Internet. Fascinating and wonderful minds in all collection of this GNU open source resources.
So please do not ever sudo and modify anything in /etc/* unless your in the know or are an Administrator or Advanced User. yes you can setup Static systems and use /etc/hosts file and few others for networking naming ip listing etc
dns and routing characteristics - but in most - think read google it first then proceed but can know you may get funny mirrored or " as in my response" Duplicated path statements - which is not harmful just annoying with a want to find an
answer.

May the force be with you all - may GNU outlive shine on - Thx mr B Torvolds for this wonderful Operating System and the gazillions out there - doing it Luv ye-All.

ps: under the hood MS windows really since 3.5 has and is all based on Sco Unix. buttered up so deep in Widget and gui devo - to what it is 2day - but .. and apparently iOS is based on OpenBSD another flare in features rich with Unix/Linux mix - also nicely developed. But as most - good for point and click users. !! ( *NIX is King. ).
pss: always good to do the reading on System Boot Up Procedures for Debian to which we're floating on as our deep level of OS. Ubuntu based Mint and some flavors of Mint are Debian direct Based. Before 17.3. Mint users are lucky this is
one super nice distro and has nice feature rich capabilities.

User avatar
DetroitGeek
Level 1
Level 1
Posts: 5
Joined: Sat Nov 13, 2010 8:34 am
Location: Metro Detroit Area

[Solved]Re: Problem modifying $PATH

Post by DetroitGeek » Sun Feb 07, 2016 8:10 pm

Lots of good stuff - thanks everyone!
If it was easy, anyone could do it.

lmuserx4849

Re: [Solved]Problem modifying $PATH

Post by lmuserx4849 » Wed Mar 09, 2016 7:38 am

Check to see if it exists first. Edit $HOME/.bashrc and add:
if [[ -d "$HOME/jhoward/scripts" ]] ; then
if [[ "${PATH}" != *"$HOME/jhoward/scripts"* ]] ; then
export PATH="$HOME/jhoward/scripts:$PATH"
fi
fi

Post Reply

Return to “Scripts & Bash”