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

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

asked 2022-02-16 20:00:25 -0500

PumpkinIcedTea gravatar image

updated 2022-02-16 20:00:52 -0500

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 <sourcepath>

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

Would appreciate the help, thanks !

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2022-02-16 22:11:11 -0500

sayantand gravatar image

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.

edit flag offensive delete link more
0

answered 2022-02-17 05:13:00 -0500

electrophod gravatar image

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.

edit flag offensive delete link more

Comments

1

Hi could you elaborate on how ypu do these aliases?

PumpkinIcedTea gravatar image PumpkinIcedTea  ( 2022-02-18 01:17:33 -0500 )edit

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

electrophod gravatar image electrophod  ( 2022-02-18 02:00:03 -0500 )edit
0

answered 2022-02-17 04:07:24 -0500

ljaniec gravatar image

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/... Just be sure to have the correct chain of sourcing: http://wiki.ros.org/catkin/Tutorials/...

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"

edit flag offensive delete link more

Comments

2

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.

gvdhoorn gravatar image gvdhoorn  ( 2022-02-17 05:06:43 -0500 )edit

TIL, thank you, sorry for misleading there

ljaniec gravatar image ljaniec  ( 2022-02-17 10:14:53 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-02-16 20:00:25 -0500

Seen: 1,063 times

Last updated: Feb 17 '22