Originally Posted by
WebDrake
Hello all,
I have various programs that are installed in subdirs of /opt. In order to allow them to run, I obviously need to add the appropriate dirs to PATH.
My "solution" was to add a little script, opt.sh to /etc/profile.d/ containing the following code:
Code:
for d in /opt/*/bin; do
PATH="$PATH:$d"
done
... but this has at least 2 problems: first, it means that if I ever rerun the profile script while logged in, $PATH winds up containing multiple entries; and in any case I believe it's not considered very safe.
Can anyone advise at least how to get rid of the multiple entries, and (better) on any superior solutions for packages installed in subdirs of /opt ... ?
Thanks & best wishes,
-- Joe
Just check for the existence of the directory 'd' in PATH before attempting to augment PATH variable. Perhaps:
Code:
for d in /opt/*/bin; do
echo $PATH | grep "$d" > /dev/null
if [ $? -ne 0 ]; then
PATH="$PATH:$d"
fi
done
I'm not an expert Bash script developer, so perhaps the above can be condensed for efficiency purposes.
Bookmarks