Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid duplicated paths in environment variable #61

Open
jmirabel opened this issue Jul 13, 2020 · 3 comments
Open

Avoid duplicated paths in environment variable #61

jmirabel opened this issue Jul 13, 2020 · 3 comments

Comments

@jmirabel
Copy link
Contributor

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.

prepend_to_env_var()
{
  var=$1
  value=$2
  if [ -z "${!var}" ]; then
    export ${var}=${value}
  else
    export ${var}=${value}:${!var}
  fi
}
@florent-lamiraux
Copy link
Contributor

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

@jmirabel
Copy link
Contributor Author

You are right, it does not. I forgot to add the check for value in var...

@jmirabel
Copy link
Contributor Author

Following https://www.cyberciti.biz/faq/bash-find-out-if-variable-contains-substring/ should solve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants