On Fri, Jun 24, 2022 at 6:04 PM Jon LaBadie <jonfu@jgcomp.com> wrote:
On Fri, Jun 24, 2022 at 07:36:00AM -0800, Roger Heflin wrote:
>Trick is add this around the path add.
>
>If [ $path_add -ne 1 ] ; then
>Path addition code
>Path_add=1
>Fi
>
>That only runs it once.
>
>On Fri, Jun 24, 2022, 4:09 AM Anil F Duggirala <anilduggirala@fastmail.fm>
>wrote:
>
>> hello,
>> I would like to change the $PATH environment variable permanently, to
>> be able to execute a program more quickly.
>> I have tried adding a new line: export PATH=$PATH:/my/path , to my
>> .bashrc .
>> When I log in again, I see that $PATH is now: $PATH:/my/path/:/my/path,
>> my directory has been appended twice.
>> I don't know exactly what the "export" command actually does, so I am
>> lost here.
>> thanks for your help.

Conceptually similar to Roger's approach, I set an environment
variable "OrigPATH" to the initial PATH then assign PATH based
on OrigPATH.

# save a copy of the original path to modify
export OrigPATH=${OrigPATH:-$PATH}
# adjust PATH from OrigPATH to my tastes
export PATH=$HOME/bin:$OrigPATH:/my/path

Environment modules preserves the current environment
and then adds or modifies environment variables according
to a "modulefile".  The original has been around for decades,
there is now a lua version. Fedora uses environment modules
when building rpm's that support more than one choice for
supporting libraries.  See:

 % ls /usr/share/modulefiles/mpi
mpich-x86_64  openmpi-x86_64

--
George N. White III