Open jmirabel opened 4 years ago
I have tested with the following config.sh
and it seems that sourcing several times does not prevent duplication of paths.
export INSTALL_HPP_DIR=$DEVEL_HPP_DIR/install
export ROBOTPKG=/opt/openrobots
export ROS=/opt/ros/melodic
prepend_to_env_var()
{
var=$1
value=$2
if [ -z "${!var}" ]; then
export ${var}=${value}
else
export ${var}=${value}:${!var}
fi
}
prepend_to_env_var PATH $ROS/bin
prepend_to_env_var PATH $ROBOTPKG/sbin
prepend_to_env_var PATH $ROBOTPKG/bin
prepend_to_env_var PATH $INSTALL_HPP_DIR/bin
prepend_to_env_var PATH $INSTALL_HPP_DIR/sbin
prepend_to_env_var PKG_CONFIG_PATH $ROS/lib/pkgconfig
prepend_to_env_var PKG_CONFIG_PATH $ROBOTPKG/lib/pkgconfig
prepend_to_env_var PKG_CONFIG_PATH $INSTALL_HPP_DIR/lib/pkgconfig
prepend_to_env_var PYTHONPATH $ROS/lib/python2.7/dist-packages
prepend_to_env_var PYTHONPATH $ROBOTPKG/lib/python2.7/site-packages
prepend_to_env_var PYTHONPATH $INSTALL_HPP_DIR/lib/python2.7/dist-packages
prepend_to_env_var PYTHONPATH $INSTALL_HPP_DIR/lib/python2.7/site-packages
prepend_to_env_var LD_LIBRARY_PATH $ROS/lib
prepend_to_env_var LD_LIBRARY_PATH $INSTALL_HPP_DIR/lib64
prepend_to_env_var LD_LIBRARY_PATH $ROBOTPKG/lib
prepend_to_env_var LD_LIBRARY_PATH $INSTALL_HPP_DIR/lib
prepend_to_env_var ROS_PACKAGE_PATH $ROS/share
prepend_to_env_var ROS_PACKAGE_PATH $ROBOTPKG/share
prepend_to_env_var ROS_PACKAGE_PATH $INSTALL_HPP_DIR/share
prepend_to_env_var CMAKE_PREFIX_PATH /usr
prepend_to_env_var CMAKE_PREFIX_PATH $ROS
prepend_to_env_var CMAKE_PREFIX_PATH $ROBOTPKG
prepend_to_env_var CMAKE_PREFIX_PATH $INSTALL_HPP_DIR
if [ -f "${INSTALL_HPP_DIR}/etc/hpp-tools/bashrc" ]; then
source "${INSTALL_HPP_DIR}/etc/hpp-tools/bashrc"
fi
You are right, it does not. I forgot to add the check for value
in var
...
Following https://www.cyberciti.biz/faq/bash-find-out-if-variable-contains-substring/ should solve the issue.
I open this issue to keep track of the snippet below which can be used to avoid duplicated paths in environment variables. This is of very low priority.