Launch actions. What's the difference between SetEnvironmentVariable and AppendEnvironmentVariable?

Hi,

Can someone tell me what is the difference between SetEnvironmentVariable and AppendEnvironmentVariable?

With both actions you can assign a value to an environment variable, so I can’t figure out what the difference is.

Regards.

The difference is in the word “set” vs “append”.

If you are familiar with environment variables in Linux, you would know that some of them should be appended rather than set. One such is the PYTHONPATH environment variable. Let’s see how that works.

user:~$ echo $PYTHONPATH
/home/simulations/public_sim_ws/devel/lib/python2.7/dist-packages:/opt/ros/kinetic/lib/python2.7/dist-packages:/home/simulations/public_sim_ws/src/all/ros_basics_examples/python_course_class:/home/simulations/public_sim_ws/src/ros_basics_examples/python_course_class:/home/simulations/public_sim_ws/src/all/kinematics_course_utils/kinematics

You’ll notice that there are a number of paths there, separted by the character :.

Python modules, such as your ROS package, will add to (append) this variable. If they were to overwrite (set) it, they would remove all other paths in the variable and some programs would not work. Let’s say I have a new path I would like to add: /home/user/caktin_ws/my_package.

# This is Append: it retains existing paths in the variable
export PYTHONPATH="$PYTHONPATH:/home/user/catkin_ws/my_package"

# This is Set: it clears all existing paths in the variable
export PYTHONPATH="/home/user/catkin_ws/my_package"

I hope this clarifies.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.