2

I am using ROS (Robot Operating System www.ros.org). I have to source .sh file every time. What it means ?

source /opt/ros//setup.bash

or have to enter this line in .bashrc file

Why we need this ?

Volker Siegel
  • 13,065
  • 5
  • 49
  • 65

1 Answers1

7

We can't know what it does exactly is unless you show us the contents of /opt/ros/setup.bash. In general, sourcing a script means that the script is executed but in your current shell. It is often used to set up certain variables and make them available in your current session.

For example, the script below simply defines the variable foo and gives it the value of bar:

foo=bar

If I save that as foo.sh and source it, the variable will be available to me:

## Before sourcing, $foo is empty
$ echo $foo
$ 
## Once I source, $foo is defined
$ source foo.sh
$ echo $foo
bar
$
terdon
  • 100,812