Is there some best practice of adding a path to $PATH via a shell script permanently via a shell script and have it accessible? I believe I have only seen temporary solutions, via export PATH=$PATH:<path/to/add> but suggested solutions like
echo "export PATH=\"<path/to/add>:\$PATH\"" >> ~/.bashrc
seem to add a "export PATH..." line every time the script is called. I am looking for something like this:
<install.sh>
#! /bin/sh
new_path="/foo/bar"
echo $PATH
set path variable
updatePath($PATH, new_path) <---- how to do this
#load path variable in current script
source ~/.bashrc
echo "updated path":
echo $PATH
expecting the following output of running ./install.sh:
/usr/local/bin:/usr/bin
updated path:
/usr/local/bin:/usr/bin:/foo/bar
Any working solutions or best practices? I want to have the /foo/bar stored in $PATH permanently and accessible directly within the install.sh script as well as from the command line. Ubuntu 22.04.2 LTS