c++shellcmakeroscatkin

Add shell script as executable to catkin package to use with rosrun


When using a catkin package it is possible to start the c++ executables, that were added in the CMakeLists.txt, using the command rosrun <package_name> <executable_name> from anywhere on the computer.

Is there a way to add a shell script as an executable to the catkin package so that it can be called using rosrun <package_name> <script.sh>?


Solution

  • Yes it is. You can do this by performing the following steps:

    You need to place your script in the scripts folder of your package. Also the script needs to be marked as executable (chmod +x your_script.sh).

    After sourcing your workspace, you can run and launch the script with ROS tools like

    rosrun your_package your_script.sh
    

    Note that you need to add your script also to the CMakeLists.txt in case of installation:

    install(PROGRAMS scripts/your_script.sh
      DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    )