# roslaunch

This note is trying to answer the following two questions.

* What happens after I type `roslaunch` in the terminal?
* How could the Linux know the commands and help me auto-complete it?

We will introduce some basics about environment variables in Linux and the concept of search path.&#x20;

### Environment Variables in Linux

![Three important PATH env in ROS](https://3310611219-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LwRt8_BWYScDaMKj3wZ%2F-M1dERe_oWFO8E0QqbgT%2F-M1dI_O5-keN2nnaCWcd%2Fpath.JPG?alt=media\&token=fe999c85-419d-4b68-91c9-83d9f3e660d1)

First of all, no matter what kind of command you type in the terminal, it must exist in one of the directories indicated in the **PATH** environment variable. This is where the Linux terminal will search first. For example, `ls` `cat` commands are in `/bin` directory;  `python` command is under directory`/usr/bin`.&#x20;

To auto-complete, the system must know all possible commands given the existing characters you type in the terminal. This is somehow like to complete a English word given the first X characters, where you can search in a dictionary for all possible solutions. Likewise, Linux can search all executables in the directories listed in PATH env. Once it finds there is a **unique** solution, it will help you complete it.

To find the exact path for each command you type in, you can use `which` command. For example, if you try`which python` in the terminal, it will return to you the search result of the command `python`. You can also do this for the `which` command itself. Try it.

```
user@hostname$ which python
/usr/bin/python
```

### Where ROS commands are installed?

Next, we will talk about how ROS handles the search path.

For all ROS-related commands, in order to run in the terminal, it has to be an Linux executable. This is an universal rule in Linux with no exceptions. Note that the first directory listed in PATH env is `/opt/ros/kinetic/bin`. You got it! This is where all the ROS commands exist. Open the folder and you will find python scripts like `roslaunch`, `rqt_graph`, etc.

Go ahead and open the `roslaunch` script. What? Only two lines of code?&#x20;

```
#!/usr/bin/python

# Software License
# etc...

import roslaunch
roslaunch.main()
```

Yes, it is. `roslaunch` was installed as a Python 2.7 library in the system.&#x20;

Then the following question is, how could python know where to import `roslaunch`?

Check the first directory in the **PYTHONPATH** env!

`/home/hteng/catkin_ws/devel/lib/python2.7/dist-packages`

Here we go! Open this folder and you will see all the ROS-related python programs.

### How could ROS auto-complete the package name?

The third environment variable we would like to talk about is the **ROS\_PACKAGE\_PATH**. This is where ROS will search when you are typing a package name right after `roslaunch` and `rosrun`.&#x20;

```
roslaunch turtlebot_br    [press Tab, then it becomes]
roslaunch turtlebot_bringup
```

How could ROS know all the possible package names? I believe now you can guess the answer. Yes, it will search all the directories listed in the **ROS\_PACKAGE\_PATH**.

That's all for today! Have fun!
