I am doing a script that is installing ros and after installing it, compiling a workspace with catkin_make.
I found the solution to solve my problem but I can't explain the reason. I have a file called install.bash that is calling others:
#!/bin/bash
source 01_install_ros.bash
What is important is in 01_install_ros.bash
:
# variable not set because it is done in the script setup.bash of ros
echo "before source in 01_install_ros"
echo "ROS_ROOT: "$ROS_ROOT
whereis catkin_make
echo ""
echo "source /opt/ros/kinetic/setup.bash" >> $HOME/.bashrc
# doesn't set the variables
source "$HOME"/.bashrc
# the solutions
source /opt/ros/kinetic/setup.bash
# variables not set if I use the source of .bashrc
echo "after source in 01_install_ros"
echo "ROS_ROOT: "$ROS_ROOT
whereis catkin_make
echo ""
As written in comments, sourcing .bashrc instead of directly setup.bash doesn't work. I really don't get why. Can you explain me?
.bashrc
is intended to be read by the Bash itself. Why do you think it might be necessary to do it in a script?01_install_ros.bash
that is sourcing setup.bash from ros. And I need to source it.source /opt/ros/kinetic/setup.bash" at the end of
.bashrc. I do that in
01_install_ros.bash`. And I need to source this setup.bash to have access to catkin_make in $PATH. What I don't understand is why I don't have this access when I am sourcing .bashrc. I hope to be clear.exec bash
to start a new Bash, which has read the updated.bashrc
.source ~/.bashrc
? I know how to solve it:source /opt/ros/kinetic/setup.bash
directly.