ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
3

What does source command actually do?

asked 2014-07-30 08:32:04 -0600

Tomaszz gravatar image

updated 2016-10-24 09:06:53 -0600

ngrennan gravatar image

Hi, I've read that $ source devel/setup.bash is the same as $ .devel/setup.bash and that it reads and executes setup.bash script in the current shell. Opposite to this $ ./devel/setup.bash what would run the same script but launching new shell.

So we want to run $ source <filename> command everytime we open new terminal.

Following questions are:

  1. Its not clear to me what actually am I doing with the source command. Where can I find this bash file that contains these enviroment variables, so I can track what's going on?
  2. Can I permanently add required enviromental variables so I don't have to do it manually every time I open a terminal? What are pros and cons of doing such.
  3. I followed tutorial. Entered this:

$ source devel/setup.bash

$ echo $ROS_PACKAGE_PATH

Which gave me:

/home/username/Workspace/ros-workspace/tutorial_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks

Then I entered this:

$ source /opt/ros/indigo/setup.bash

$ echo $ROS_PACKAGE_PATH

Which gave me:

/opt/ros/indigo/share:/opt/ros/indigo/stacks

Why such sequence erased my ~/home... path from bash??

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
12

answered 2014-07-30 09:42:19 -0600

mjcarroll gravatar image

When you "source" something in bash, it will execute each line of the file as is it were typed into the current shell. This is contrasted to actually executing the script, which will be run in a new shell.

The setup.bash file is merely adding environment variables to your path to allow ROS to function.

You can add the source setup.bash command to your ~/.bashrc file, so that it will be executed every time that you open a new shell.

Your third sequence shows you first using a local workspace, which is overlaying the system indigo installation. When you source the /opt/ros/indigo/setup.bash file, you are no longer using the local workspace, but rather only the system installation, which is why the local workspace variables are no longer available.

You should always source your local workspace setup last.

edit flag offensive delete link more

Comments

Well explained. I started to answer to early.

BennyRe gravatar image BennyRe  ( 2014-07-30 09:48:52 -0600 )edit

how do i remove /opt/ros/indigo/stacks

bonzi gravatar image bonzi  ( 2017-03-17 09:01:03 -0600 )edit
0

answered 2014-07-30 09:46:53 -0600

BennyRe gravatar image
  1. From my knowledge what gets added to your ROS_PACKAGE_PATH is not hard coded. It gets added by a crawler/parser I think. So there's no Bash file saying export ROS_PACKAGE_PATH=/home/user/path/x:/path/y. Please correct me if I'm wrong.

  2. Yes you can add environment variables permanently in your .bashrc. As the ROS installation tutorial says you also can add the source command to your .bashrc. If you work with only one ROS distro and one workspace I don't see any major cons of adding variables or sources to your .bashrc. If you have multiple distros or workspaces it may be better to source them by hand.

  3. The paths in your home folder get erased because the /opt/ros/indigo/setup.bash doesn't know anything about your workspace. It knows only the packages installed by debians.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2014-07-30 08:32:04 -0600

Seen: 25,553 times

Last updated: Jul 30 '14