Robotics StackExchange | Archived questions

How to write multiple "source" commands in bash.rc

Hi guys, I have different robots in different files, how do I source multiple workspaces in my bash.rc? I remembered seeing a method somewhere that was something like this :

For "Robotname"

source

But I can't find the exact syntax...

Would appreciate the help, thanks !

Asked by PumpkinIcedTea on 2022-02-16 21:00:25 UTC

Comments

Answers

Just write them one after another for example:

source ~/catkin_ws/setup.bash
source ~/catkin_ws_2/setup.bash

Make sure to run

catkin_make

in each one of them separately.

Asked by sayantand on 2022-02-16 23:10:35 UTC

Comments

I am using in my ~/.bashrc the standard way, e.g. for ROS2:

# ros2_ws workspace
source ~/ros2_ws/install/setup.bash

# dev_ws workspace
source ~/dev_ws/install/setup.bash

# nav2_ws workspace
source ~/nav2_ws/install/setup.bash

In ROS1 you can do something similar, I think? Based on: http://wiki.ros.org/catkin/Tutorials/workspace_overlaying Just be sure to have the correct chain of sourcing: http://wiki.ros.org/catkin/Tutorials/workspace_overlaying

You can try to have aliases too, e.g. I had at one time in the past two of them, alias goros2galactic="source /opt/ros/galactic/setup.bash" and alias goros2foxy="source /opt/ros/foxy/setup.bash"

Asked by ljaniec on 2022-02-17 05:07:24 UTC

Comments

Contrary to ROS 2, you cannot really source multiple setup.bash at the same time in ROS 1 -- or at least not multiple sibling workspaces.

And if you're overlaying, you only need to source the outermost layer.

Asked by gvdhoorn on 2022-02-17 06:06:43 UTC

TIL, thank you, sorry for misleading there

Asked by ljaniec on 2022-02-17 11:14:53 UTC

In ROS1 you cannot source multiple workspaces at the same time (in the same environment or same terminal). You can only source one workspace at a time along with the setup.bash of ROS.

So what I usually do is create an alias in my .bashrc file with the name of every workspace commanding to source that workspace when that specific alias is run.

For e.g. I have a workspaces abc_ws and xys_ws. I will create aliases abc_ws and xyz_ws in my .bashrc file as follows :

alias abc_ws='source <path_to_abc_ws>/devel/setup.bash'

alias xyz_ws='source <path_to_xyz_ws>/devel/setup.bash'

And call them whenever I need the source the workspaces (one in a single environment or terminal)

Note : You can have more than one terminals open at the same time with different ROS workspaces sourced in them.

Asked by electrophod on 2022-02-17 06:13:00 UTC

Comments

Hi could you elaborate on how ypu do these aliases?

Asked by PumpkinIcedTea on 2022-02-18 02:17:33 UTC

@PumpkinIcedTea As I've explained in my example, you just need to set the aliases in the .bashrc file

Asked by electrophod on 2022-02-18 03:00:03 UTC