I'd like to check two things:
* Whether a given path is not already in the $PATH variable
* Whether the given path already exists
If both are true, I'd like to add the given path to the $PATH variable.
I can add the given path, and test for the existence of the given path.
I can write expressions that work to detect the given path in $PATH.
What I don't seem able to do is combine all that in a script.
Here's what I have for the script:
#!/bin/bash
# A short script for testing some code.
# pelican seems to like local installations here.
SUBSTR="${HOME}"/\.local/bin/
echo Substr is "${SUBSTR}"
# if [[ ! ${PATH} =~ .*/home/charles/.local/bin.* ]] ; then
if [[ $( echo "$PATH" | grep -E -v "${SUBSTR}" ) ]] ; then
echo Substring NOT found.;
if [ -d "${HOME}/.local/bin/" ] ; then
echo Adding to \$PATH
PATH=${HOME}/.local/bin:$PATH
fi
else
echo Substring found!;
fi
I call the script with the . operator: ". test.sh"