Solution
Explanation
[[ ! "$PATH" == *your_path* ]]
checks if PATH contains your new path already, hence avoiding duplicates. This does not work well for nested bin directories, but that rarely happens.
${parameter:+word}
uses word
if parameter
is null or unset.
Therefore, if PATH is unset, no additional :
is added before your new path.
References
- bash(1)