I have a somewhat long path. I construct my path from these components.
PART1="/home/$USER/.local/bin:/home/$USER/bin:/usr/local/sbin:/usr/local/bin"
PART2="/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
PART3="/usr/local/bin:/home/local/bin:/usr/bin/mh:/home/$USER/go/bin"
export PATH=${PART1}:${PART2}:${PART3}
from within ~/.bash_profile running the above code renders what's below.
/home/kevinc/.local/bin:/home/kevinc/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/bin:/home/local/bin:/usr/bin/mh:/home/kevinc/.go/bin:/home/kevinc/go/bin
But, from a fresh terminal window that used ~/.bash_profile the path in that shell is below. Notice that the path "." got prepended, and that the last three directories didn't end up in the final result.
.:/home/kevinc/.local/bin:/home/kevinc/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/bin
I changed the order of PART2 & PART3 in my script, and the output directory list stayed in the above order.
I wondered if there is a maximum length for environment variable size. That questions has been answered numerous times by various people looking up limits source code used in Linux. Other decided to continue increasing their environment variable size until the program stopped working right. Those answers were in the 10k to 30M in size. I think that my 244 character size isn't likely a limit.
For what it's worth, I'm running Linux Mint 21.3, one rev. behind the newest version.
Yes, I ran my code through http://shellcheck.net
.doesn't just show up on its own, it's being added somewhere; review all of your login/resource files (.bashrc,.profile,.bash_profile); do you recall if you've updated any of the default resource files (eg,/etc/bash.bashrc)? the fact you can change the order of appended variables but see no difference supports the fact that you're buildingPATHin some other file; as for the limitation onPATHlength ... I'm runningubuntu 22.04 / bash 5.1.16and I have no problem buildingPATHwith your code (ie, I don't hit a length limitation)$PATH, and there's little harm in simply writing a series of assignments likePATH=path1:$PATH; PATH=path2:$PATH; # etc`.PART3contains/home/$USER/go/binbut output ("from within ~/.bash_profile") has/home/kevinc/.go/bin:/home/kevinc/go/bin(note the additional.go/bin) so perhaps a copy-paste error along the way when posting; (2)PART1andPART3both contain/usr/local/binso if length is a concern consider eliminating one (the dupe does show in final terminal window output as well).export PATH=/opt/path:$PATHas much as they want to populate the path variable without clobbering each other.